Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have my input schema as BigDecimal and output Schema as BigDecimal.
I must have 2 decimal places in my output.
My code is giving me an error since it cannot convert from BigDecimal to String:
String.valueOf(row1.Account_currency == BigDecimal.valueOf(8888888888888.00))
or should it be something like this. This is giving an error too
(row1.Account_currency == BigDecimal.valueOf(8888888888888.00))
This is in tMap.
the first argument on the method setScale (in my example 1) specify the number of digit after (point or coma) of a big decimal.
So if you want 2 digit after coma set it to 2
example
row1.Account_currency = 12345.0000
row1.Account_currency.setScale(1,Big Decimal.ROUND_DOWN) = 12345.0
row1.row1.Account_currency.setScale(2,Big Decimal.ROUND_DOWN) = 12345.00
@Edith Not defined ,check the below link to do conversion form BigDecimal to Sting.
https://community.talend.com/s/feed/0D53p00007vClLlCAK
Thanks,
Manohar
HI edi ,You can go to the code view (Ctrl +G) click on the red square and then send us the associated code line.
to set big decimal places you can use : row1.Account_currency.setScale(1, BigDecimal.ROUND_DOWN)
here row1.Account_currency is the input value , 1 is the decimal place and round_Down : round down,
if input decimal is 8888888888888.00 the result is 8888888888888.0
if you want to round up :
row1.Account_currency.setScale(1, BigDecimal.ROUND_UP)
Send me Love and Kudos
Hi gjeremy,
This is helpful, but will this give me 2 decimal places instead of one for my output?
the first argument on the method setScale (in my example 1) specify the number of digit after (point or coma) of a big decimal.
So if you want 2 digit after coma set it to 2
example
row1.Account_currency = 12345.0000
row1.Account_currency.setScale(1,Big Decimal.ROUND_DOWN) = 12345.0
row1.row1.Account_currency.setScale(2,Big Decimal.ROUND_DOWN) = 12345.00
gjeremy,
Thanks! Excellent...It all worked.
Question: BigDecimal.ROUND_UP and BigDecimal.ROUND_DOWN gave me the same output. Where will I see the difference with these two options?
I take it from the Java doc :
ROUND_DOWN
Rounding mode to round towards zero. Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never increases the magnitude of the calculated value.
ROUND_UP
Rounding mode to round away from zero. Always increments the digit prior to a nonzero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.