Friday 25 November 2011

Currency Custom Formatting in Java

To format numbers like currency without currency symbol and without grouping it is enough to declare:
NumberFormat format = new DecimalFormat( "#####0.00" );

If we need to change the locale formatting, then we have to add:
DecimalFormatSymbols dfs = new DecimalFormatSymbols( Local.UK );
NumberFormat format = new DecimalFormat( "#####0.00", dfs );

For more details consult Java API - DecimalFormat.

No comments: