Issue convert string to BigDecimal and dividing by 100?

Four Stars

Issue convert string to BigDecimal and dividing by 100?

In tmap,

my source column called ProdPct is string type and lookup table column is called ProdPct is BigDecimal.

Trying to convert the source to match to ProdPct and it is not matching.  

 

used this expression to convert string to BigDecimal and it is not working.

new BigDecimal(Numeric.convertImpliedDecimalFormat("9V99",Source.Prodpct)) 

 

Source table:

0

10

20

30

 

Lookup table:

0.00

0.10

0.20

0.30

 

used tLog and shows as follow:

0

0.100000001490116119384765625

0.20000000298023223876953125 

0.300000011920928955078125  

 

What is the syntax to see the results as follow?

0.00

0.10

0.20

0.30

 

 

 

Nine Stars

Re: Issue convert string to BigDecimal and dividing by 100?

The BigDecimal(double) constructor have some problems, is preferrable that you uses BigDecimal(String) or BigDecimal.valueOf(double).

 

The BigDecimal(double) documentation explain about this behavior:

  1. The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
  2. The String constructor, on the other hand, is perfectly predictable: writing new BigDecimal("0.1") creates a BigDecimal which is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the String constructor be used in preference to this one.
  3. When a double must be used as a source for a BigDecimal, note that this constructor provides an exact conversion; it does not give the same result as converting the double to a String using the Double.toString(double) method and then using the BigDecimal(String) constructor. To get that result, use the static valueOf(double) method.