One Star

[resolved] Output format for double values

Hi, all
I need to obtain a double value which has no exponent in an csv file. The file is from a tfileOutputdelimited. In my files I got these things : 1.0137901051E8 and I need 101379010.51.
I've checked previous posts for samiliar question and found one link as below:
http://www.talendforge.org/forum/viewtopic.php?id=7601
However I'm not totally understand how to apply above solution, can we manually change the codes?
Thanks!
5 REPLIES
One Star

Re: [resolved] Output format for double values

Hi
You can type these codes in tJava or tJavaRow.
double d = 1.0137901051E8;
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
String s=df.format(d);
System.out.println("d = " + s);

Regards,
Pedro
One Star

Re: [resolved] Output format for double values

Hi, I append below codes into a tJavaRow component:
java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
output_row.TDCash = df.format(input_row.TDCash);
output_row.SDCash = df.format(input_row.SDCash);
output_row.Adjust = df.format(input_row.Adjust);
However when running, I got below errors:
Exception in component tJavaRow_1
java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at talenddemosjava.poms_cash_adjust_0_1.POMS_Cash_Adjust.tFileInputDelimited_1Process(POMS_Cash_Adjust.java:2392)
at talenddemosjava.poms_cash_adjust_0_1.POMS_Cash_Adjust.runJobInTOS(POMS_Cash_Adjust.java:3917)
at talenddemosjava.poms_cash_adjust_0_1.POMS_Cash_Adjust.main(POMS_Cash_Adjust.java:3785)
It seems java met a type mismatch error. Can u help to have a look?
One Star

Re: [resolved] Output format for double values

Or I'm not sure how to use tJava or tJavaRow component, can anybody give an example?
One Star

Re: [resolved] Output format for double values

Hi
input_row.TDCash, input_row.SDCash and input_row.Adjust should be double/Double data type.
The output columns should be String.
Regards,
Pedro
One Star

Re: [resolved] Output format for double values

I found the problem. It's also a NULL pointer problem. After I made changes as below, the problem is resolved:
if (input_row.Adjust != null)
{output_row.Adjust = df.format(input_row.Adjust);}
Thanks!