Decimal format issue

0

Hello,

I have a decimal issue in my report. I use the expression: new java.text.DecimalFormat("##0.0").format($F{score})

and I want decimals with point (.) not with comma (,) in the 'score' value. I am using jasperstudio on windows 10.

How can I fix this, please?

Regards,

MAC

xmcamino's picture
Joined: Sep 6 2015 - 7:07pm
Last seen: 4 weeks 4 hours ago

1 Answer:

0

Hi xmcamino,

What is the type of your field ? For a double or a Big Decimal you can use this : String.format("%,.2f",$F{field_name})

.2f is for a dot as a separator then 2 floating point on a decimal number. But my locale is 'France' on my PC so the dot become a comma.

Examples :

System.out.format("%.3f%n", pi);     // -->  "3.142"
System.out.format("%10.3f%n", pi);   // -->  "     3.142"
System.out.format("%-10.3f%n", pi);  // -->  "3.142"
System.out.format(Locale.FRANCE,"%-10.4f%n%n", pi); // -->  "3,1416"

https://docs.oracle.com/javase/tutorial/java/data/numberformat.html

You can check on your locale or set the locale directly in the format function.

Hope it will help you,

Yann

Yann22300's picture
Joined: Apr 29 2015 - 1:10am
Last seen: 1 week 1 day ago
Feedback