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.
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/
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?
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.
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.
If the input file contains "123,4" and not "123.4" it works fine.
But I can't change the input file.