One Star

How to convert from minus sign of BigDecimal value to plus sign in tMa

Hello,
Could anyone please teach about this issue.
There is minus value of Big decimal in Excel i wanna input to oracle DB.
How can i convert these values to plus sign in tMap?
I wanna convert only minus sign, plus sign value must be no change.
Does anyone know method to solve this issue?

Thanks!
Regards,
22 REPLIES
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
You can try tReplace.
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi Pedro,
I tried tReplace component but it couldn't replace minus sign.
I just wanna remove minus sign from only values which have minus sign.
Could this component replace even value of BigDecimal as string of minus sign such as '-'?
Following are expression I wrote.
Input column || Serch || Replace With
amount(bigdecimal) '-' ''
It shouldn't use single quart?
Thanks!
Regards,
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
I'm afraid this is a bug.
Because when I check "simple mode", it doesn't replace minus with "".
Then I check "Advanced mode", it works.
Do you encounter the same issue?
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi Pedro,
I have encounter this issue first time.
It has no run when i use single quart or double quart for this component's settings.
Probably these quart are for some strings.
When I removed these quart,it is run but minus sign are not replaced.
How did you write expression for this component?
What should I do next?
Regards,
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
Hope this image can help you.
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi Pedro,
I tried using expression you uploaded.
But it didn't run and displayed an error like following.
<Error Message>
Method of StringUtils which is repalceALL(string,string,string) can't use argument (BigDecimal,string,string)
Sorry,If you can't read.
I translate from Japanese to English this error message.
Did you use column of BigDecimal?
Regards,
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
Got it.
Change Data type into String.
Then you will get correct result.
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi Pedro,
I have to replace with type of BigDecimal.
Because, it need to be same with type of DB column I wanna load.
How can i solve this issue?
Regards,
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
You can make a conversion here.
Convert Decimal into String. Then use tRaplace.
In the end, change it back to Decimal.
Decimal to String: .toString() method.
String to Decimal: new BigDecimal(String string);
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Can you multiply by -1?
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Why would you convert a BigDecimal to a String only to remove negative signs? There is a mathematical function to do exactly that called "absolute value".
Just call
row.number.abs()
on your number in a tMap and you're fine. Multiplying by -1 would change the sign of all positive values too and does not meet the requirement.
You should avoid converting to Strings whenever possible, toString() is a technical method. I am a little bit astonished the Talend team in this forum does not know this.
Cheers,
j
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi Pedro,
I tried method you wrote then data type couldn't change string into decimal in output from tReplace to tMap.
Can this component replace with Decimal value?
Regards,
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
I think mathcrack's workaround is perfect.
I forgot this method.
Regards,
Pedro
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi mathcrack,Pedro
It got result i want.
Thank you very match!
Regards,
Six Stars

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Mathcrack's solution is how it is supposed to work. BigDecimals are immutable. You cannot change them with normal arithmatic operations, and converting to string is not required or efficient. Calling the absolute value method is the correct solution.
Six Stars

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

absolute method will not work for bigdecimal,
so we can not use abs() function
Raghunath Lingutla
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

And why shouldn't abs() work for BigDecimal?
When checking http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigDecimal.html you'll see abs() is a standard BigDecimal method.
Regards,
Arno
Six Stars

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

i am using Mathematical.ABS(row3.ID) in tmap where ID is of BigDecimal datatype,
it is giving error "The method ABS(double) in the type Mathematical is not applicable for
the arguments (BigDecimal)
Raghunath Lingutla
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi
If the column ID is BigDecimal type, try this.
row3.ID.abs();

Regards,
Pedro
Six Stars

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

thank you i got my answer
Raghunath Lingutla
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi,
I have the same problem, but when I apply the .abs() method on Tmap, it's giving error:
"Exception in component tMap_2 java.lang.NullPointerException at ..."
The code at this line -> "MyBigDecimal.abs()"
I use TIS 4.1.3.
Thanks
One Star

Re: How to convert from minus sign of BigDecimal value to plus sign in tMa

Hi,
I have the same problem, but when I apply the .abs() method on Tmap, it's giving error:
"Exception in component tMap_2 java.lang.NullPointerException at ..."
The code at this line -> "MyBigDecimal.abs()"
I use TIS 4.1.3.
Thanks

Sorry I don't test if my BigDecimal is NULL before.