java - Formating numbers with %1$,.2f -
i using
public static string displaynumberamount(number amount, locale locale) { string.format(locale, "%1$,.2f", amount); }
to format numbers in locale , 2 decimals.
if have number 1032 correctly formatted 1 032,00 if have number lower 1000, example 890, formatted 890 (and need 2 decimals always)
in object, values stored bigdecimals,
bigdecimal val = object.getamount(); string formattedval = displaynumberamount(val, mylocale);
can tell me why?
your code works fine me. test:
import java.math.bigdecimal; import java.util.locale; public class tester{ public static void main(string args[]){ system.out.println("999 " + displaynumberamount(new bigdecimal(999.99), locale.french)); system.out.println("1000 " + displaynumberamount(new bigdecimal(1000.99), locale.french)); system.out.println("1001 " + displaynumberamount(new bigdecimal(1001.99), locale.french)); } public static string displaynumberamount(number amount, locale locale) { return string.format(locale, "%1$,.2f", amount); } }
Comments
Post a Comment