I\'m using Java with Jasper Reports and would like to format a decimal value using this format mask \"#,##0.00\"
. At the first sight all looks fine, but I found
You can use the scriptlets mechanism.
package utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class RoundingHelper {
public static String round(BigDecimal value, RoundingMode mode, String pattern) {
DecimalFormat format = new DecimalFormat(pattern);
format.setRoundingMode(mode);
return format.format(value);
}
}
Another way is to use BigDecimal.setScale(int, java.math.RoundingMode) method (for double field):
or just (for BigDecimal field):
More info about the scriptlets in JR: Scriptlets