Feb 19

The NumberFormat and DecimalFormat classes provide support for parsing and formatting values.

They are also locale sensitive, which means they adjust the formatting and parsing rules according to the locale or region of interest.

For example in France they use a comma as a decimal separator so 5,48 is the same as 5.48 in the USA.

NumberFormat format = 
   NumberFormat.getInstance(Locale.FRANCE);
Object value = format.parse("5,48");

written by objects \\ tags: , , , , ,

Feb 19

The NumberFormat and DecimalFormat classes provide support for parsing and formatting currency values.

For example to parse a string containing a money value in the default locale you can use the following.

   NumberFormat format = NumberFormat.getCurrencyInstance();
   Object value = format.parse("$5.45");

written by objects \\ tags: , , , , ,

Feb 16

The NumberFormat class provides support for currency formatting. By current default Locale is used to determine what currency the value should be formatted in.

double value = 6.34;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String formatted = formatter.format(value);

written by objects \\ tags: , , ,