Formatting Double into a String in iReport
20,255
Solution 1
Use like below:
new DecimalFormat("0.00").format(doubleField) + "str"
Solution 2
Do the next:
- Open Properties window for your report (right-mouse click on top node in tree view -> Properties)
- Set the Language option to Java
Use such code in your text field expression:
String.format("%.2f",$V{Sum}) + " " + $F{unit}
Here
2 - number of digits after dot
$V{Sum} - Double or Floaf variable (or field - $F{...})
Author by
Gondim
Updated on July 09, 2022Comments
-
Gondim almost 2 years
I'm doing a report, that I need to join 4 variables in one. If I treat the variables separately I can format them with no problem. But when I merge them into a String, the double value comes as 0.0 instead of 0.00
How can I make it comes as the original, 0.00? The code right now looks like this:
$F{someDoubleField} + "a string" + $F{anotherDoubleField} + "another string"
It prints:
0.0 a string 0.0 another string
instead of:
0.00 a string 0.00 another string
Remember that iReport uses Java, so maybe, Java code can help me out.
-
ehrhardt over 10 yearsYou didnt answer the question
-
ehrhardt over 10 yearsthe answer would have been: new DecimalFormat("0.00").format($F{someDoubleField}) + "a string" + new DecimalFormat("0.00").format($F{anotherDoubleField}) + "another string"