One Star

Convert from BigDecimal to String

Hi guys,
My goal is to convert from source value 0.0000 (4 precision) to 0.00 (2 precision) in String format.
I noticed there is an issue when converting from BigDecimal to String. For example, my source file with value 0.0000 (I am setting it as 2 precision in BigDecimal format). Next, I am using tmap to convert it into string. (refer to my attached screen shot).
The problem is that after converting to String, the value change back to 4 precision 0.0000 instead of 0.00
3 REPLIES
One Star

Re: Convert from BigDecimal to String

Seventeen Stars

Re: Convert from BigDecimal to String

You could do this:
java.text.NumberFormat.getInstance(Locale.ENGLISH).format(Math.round(row1.my_big_decimal_value.doubleValue() * 100d) / 100d)

The precision in your input flow will not used to read / create the BigDecimal value. Length and precision are only be used if you create a table or if you use the build-in to string conversion.
One Star

Re: Convert from BigDecimal to String

Hi Jlolling,
Thanks for the information.