String "123.4" has not been converting into number field - solved

Hello,

I have a problem to format a string field "123.4" as a numbered output with format "#.##0,00" (DE) or "#,##0.00" (US) -> 123,40 or 123.40.

I use Jasper iReport 5.6.0.
My database is a csv-file which I converted from an EDIFACT INVOIC file.
In the csv-file there are number fields like price, quantity and more.

C_MENGE C_ME C_Datum C_PreisGZ
50 PCE 20140807 123.4

C_PreisGZ as java.lang.double:                                           The output is 1234.00. The decimal point wasn't recognized.

C_PreisGZ as java.lang.string:                                              The output is 123.4. The number format was ignored.

C_PreisGZ as java.lang.string with replace "." as ",":        The output is 123,4. The number format was ignored.

 

I tried to define an additional field (java.lang.double/java.lang.float/java.lang.bigdecimal) to convert the string into number:

new java.text.DecimalFormat("#,##0.00").format($F{VALUE}) 

Caused by: java.lang.IllegalArgumentException: Cannot format given Object as a Number.

If I use a constant it works fine, but if I use the field from the file...

How can I fix it?

Thank you.

jor_esterio's picture
Joined: Aug 18 2014 - 7:51am
Last seen: 1 year 6 months ago

If the input file contains "123,4" and not "123.4" it works fine.

But I can't change the input file.

jor_esterio - 8 years 11 months ago

4 Answers:

Hi ,

Please can you check that the Field  VALUE has a correct datatype of a Number/Double which could be formatted.

As you expressed that the input nature could not be changed then you could manually change the type of the field in the iReport from the proprties of the Field, locate the datatype, change it to double and possibly you could solve the issue.

 

Thanks

Ankur Gupta
http://ankurthetechie.blogspot.in/

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 3 days 20 hours ago

Hi,

thanks for your answer.

When I change the datatype of the field VALUE (or here C_PreisGZ) as double I got 1234.00 and not 123.40.

iReport ignores the Decimal Point (123.4) and that is my problem.

I need an idea to convert the incoming string "123.4", so that iReport knows it is the number 123.4.
If the value in the incoming string is "123,4" and I change the datatype of the field VALUE iReport printed 123.40.
But I cannot correct the incoming string.

Any other idea?

jor_esterio's picture
Joined: Aug 18 2014 - 7:51am
Last seen: 1 year 6 months ago

Is there a parameter which I can use, such like csv.number.decimalpoint = ","???

jor_esterio - 8 years 11 months ago

Hello,

I solved the problem.

The language in the properties of the report was "Groovy".
I changed it to "JavaScript" and now I can format the field C_PreisGZ as number and the value is 123.4.

Thank you.

jor_esterio's picture
Joined: Aug 18 2014 - 7:51am
Last seen: 1 year 6 months ago

same problem here but your solution doesnt resolve my issue.
Changed the language to javascript but still get "1234.00".
I used the field with a pattern (not your solution with new DecimalFormat)

any ideas?

heringsfilet - 8 years 5 months ago
Hello,
you can try the following alternate solution:
You change the language in the properties of the report to "Java".
Then you format the incoming field - here C_PreisGZ - as "java.lang.String".
In the report you can format the field as "java.lang.String" with the pattern "#,##0.00;-#,##0.00".
The output is 123.40.

I'll hope this will help.
jor_esterio's picture
Joined: Aug 18 2014 - 7:51am
Last seen: 1 year 6 months ago
Feedback