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: , , , , ,

Jun 11

You can tell the parseInt() method what base number system is used by the String that is being parsed.


String hex = "01001101";
int n = Integer.parseInt(hex, 2);

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