- Java I18N - Home
- Java I18N - Overview
- Java I18N - Environment Setup
- Locale Class Examples
- Java I18N - Locale Class
- Java I18N - Locale Details
- Java I18N - Display Language
- ResourceBundle Class Examples
- Java I18N - ResourceBundle Class
- NumberFormat Class Examples
- Java I18N - NumberFormat Class
- Java I18N - Format Currencies
- Java I18N - Format Percentages
- Java I18N - Set Min/Max Precision
- Java I18N - Set Rounding Mode
- Java I18N - Parsing Numbers
- DecimalFormat Class Examples
- Java I18N - DecimalFormat Class
- Java I18N - Formatting Patterns
- Java I18N - Locale Specific DecimalFormat
- Java I18N - DecimalFormatSymbols Class
- Java I18N - Grouping Digits
- DateFormat Class Examples
- Java Java - DateFormat Class
- Java I18N - Formatting Dates
- Java I18N - Formatting Time
- Java I18N - Formatting Date and Time
- SimpleDateFormat Class Examples
- Java I18N - SimpleDateFormat Class
- Java I18N - Formatting Date
- Java I18N - DateFormatSymbols Class
- Java I18N - Date Format Patterns
- Time Zones Examples
- Java I18N - UTC
- Unicode Conversion
- Java I18N - From and To String Conversion
- Java I18N - From Reader and To Writer Conversion
- Related Tutorials
- Java Tutorial
- JDBC Tutorial
- SWING Tutorial
- AWT Tutorial
- Servlets Tutorial
- JSP Tutorial
- Java I18N Useful Resources
- Java I18N - Quick Guide
- Java I18N - Useful Resources
- Java I18N - Discussion
Java Internationalization - Formatting Patterns
Followings is the use of characters in formatting patterns.
| Sr.No. | Class & Description |
|---|---|
| 1 | 0 To display 0 if less digits are present. |
| 2 | # To display digit ommitting leading zeroes. |
| 3 | . Decimal separator. |
| 4 | , Grouping separator. |
| 5 | E Mantissa and Exponent separator for exponential formats. |
| 6 | ; Format separator. |
| 7 | - Negative number prefix. |
| 8 | % Shows number as percentage after multiplying with 100. |
| 9 | ? Shows number as mille after multiplying with 1000. |
| 10 | X To mark character as number prefix/suffix. |
| 11 | ' To mark quote around special characters. |
Example
In this example, we're formatting numbers based on different patterns.
import java.text.DecimalFormat; public class I18NTester { public static void main(String[] args) { String pattern = "###.###"; double number = 123456789.123; DecimalFormat numberFormat = new DecimalFormat(pattern); System.out.println(number); //pattern ###.### System.out.println(numberFormat.format(number)); //pattern ###.# numberFormat.applyPattern("###.#"); System.out.println(numberFormat.format(number)); //pattern ###,###.## numberFormat.applyPattern("###,###.##"); System.out.println(numberFormat.format(number)); number = 9.34; //pattern 000.### numberFormat.applyPattern("000.##"); System.out.println(numberFormat.format(number)); } } Output
It will print the following result.
1.23456789123E8 123456789.123 123456789.1 123,456,789.12 009.34
Advertisements