I'm working with Talend Open Studio for Data Integration.
I've got a tFileInputPositional which creates several fields. One of them would look like this: "+0000030139808303".
I need to save those fields into a BigDecimal(20,2) so that the last two digits would be the fractional part but, when typing it in the component's schema, it simply adds ",00" at the end of the number.
So, summing up...
What I have:
+0000030139808303
What I want:
301398083,03
What I get:
30139808303,00
Could anyone help me to make it work?
Thanks!
I suspect you just want BigDecimal.movePointLeft
.
Returns a BigDecimal which is equivalent to this one with the decimal point moved
n
places to the left. Ifn
is non-negative, the call merely addsn
to the scale. Ifn
is negative, the call is equivalent tomovePointRight(-n)
. TheBigDecimal
returned by this call has value(this × 10^-n)
and scalemax(this.scale()+n, 0)
.
For example:
import java.math.BigDecimal;
public class Test {
public static void main(String [] args) {
String text = "+0000030139808303";
BigDecimal original = new BigDecimal(text);
BigDecimal shifted = original.movePointLeft(2);
System.out.println(shifted);
}
}
Output:
301398083.03
See more on this question at Stackoverflow