Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Edi1
Contributor
Contributor

Can't convert from String to BigDecimal

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.

Labels (2)
1 Solution

Accepted Solutions
gjeremy1617088143

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

 

 

View solution in original post

7 Replies
manodwhb
Champion II
Champion II

@Edith Not defined​ ,check the below link to do conversion form BigDecimal to Sting.

 

https://community.talend.com/s/feed/0D53p00007vClLlCAK

 

Thanks,

Manohar

gjeremy1617088143

HI edi ,You can go to the code view (Ctrl +G) click on the red square and then send us the associated code line.

gjeremy1617088143

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

Edi1
Contributor
Contributor
Author

Hi gjeremy,

This is helpful, but will this give me 2 decimal places instead of one for my output?

gjeremy1617088143

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

 

 

Edi1
Contributor
Contributor
Author

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?

 

gjeremy1617088143

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.