Site icon Automation Dojos

Format Decimal Numbers Using Locale

If you want to create a DecimalFormat instance for a specific Locale, create a NumberFormat and cast it to a DecimalFormat.

The java.text.DecimalFormat class is used to format numbers using a user specified formatting. This concrete subclass of NumberFormat, allows formatting decimal numbers via predefined patterns specified as String . It has a variety of features designed to make it possible to parse and format numbers in any locale.

The following example demonstrates decimal formatting as per specified locale:

The above code produces the following output:

170,180.245 - English (en)
170 180,245 - French (France) (fr-FR)
170.180,245 - German (de-DE)
Exit mobile version