Category: 10. Java Internationalization
-
DateFormat Class
java.text.DateFormat class formats dates as per the locale. As different coutries use different formats to display dates. This class is extremely useful in dealing with dates in Internationalization of application. Following example show how to create and use DateFormat Class. Example Open Compiler Output It will print the following result.
-
Grouping Digits
Using setGroupingSize() method of DecimalFormat, default grouping of numbers can be changed. Following example is illustrating the same. Example Open Compiler Output It will print the following result.
-
DecimalFormatSymbols Class
Using DecimalFormatSymbols class, the default separator symbols, grouping separator symbols etc. can be changed. Following example is illustrating the same. Example Open Compiler Output It will print the following result.
-
Locale Specific DecimalFormat
By default, DecimalFormat object is using the JVM’s locale. We can change the default locale while creating the DecimalFormat object using NumberFormat class. In the example below, we’ll use same pattern for two different locale and you can spot the difference in the output. Example Open Compiler Output It will print the following result.
-
Formatting Patterns
Followings is the use of characters in formatting patterns. Sr.No. Class & Description 1 0To display 0 if less digits are present. 2 #To display digit ommitting leading zeroes. 3 .Decimal separator. 4 ,Grouping separator. 5 EMantissa and Exponent separator for exponential formats. 6 ;Format separator. 7 –Negative number prefix. 8 %Shows number as percentage…
-
DecimalFormat Class
The java.text.DecimalFormat class is used for formatting numbers as per customized format and as per locale. Example – Format Numbers In this example, we’re formatting numbers based on a given pattern. Open Compiler Output It will print the following result.
-
Parse Numbers
Example In this example, we’re showcasing parsing of number present in different locale. Open Compiler Output It will print the following result.
-
Set Rounding Mode
Example In this example, we’re showcasing Rounding Mode. Open Compiler Output It will print the following result.
-
Example
In this example, we’re setting min and max digits for both integer as well as fractional part of a number. Open Compiler Output It will print the following result.
-
Format Percentages
Example In this example, we’re formatting numbers in percentage format. Open Compiler Output It will print the following result.