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

Jul 27

You can use the getDisplayName() in the Calendar class to get a localized (according to Locale) string for any of the Calendar fields.

For example to get the day name you can use the following:

Calendar cal = Calendar.getInstance();
String day = cal.getDisplayName(Calendar.DAY_OF_WEEK, 
   Calendar.LONG, Locale.getDefault())

If you’re looking for an algorithm to get the day of the week then try Zeller’s congruence.

written by objects \\ tags: , ,