I have a project where I need to format numbers before print them. I do it like that:
public String formatNumber(String format, long number, RoundingMode roundingMode) {
DecimalFormat df = new DecimalFormat(format);
df.setRoundingMode(roundingMode);
return df.format(number);
}
But my app need to use GWT, and I can't use DecimalFormat anymore because it's not supported. I need to use NumberFormat
from the package com.google.gwt.i18n.client.NumberFormat;
.
I format my numbers like that:
public String formatNumber(String format, long number, RoundingMode roundingMode) {
NumberFormat df = NumberFormat.getFormat(format);
return df.format(number);
}
As you can see, df.setRoundingMode doesn't exist on NumberFormat. My number is automatically rounded to the nearest decimal. However, I do not always want to have this behavior. How can I round the numbers as I wish with this class?
Thanks