I am trying to use DecimalFormat.groupingSize()
functionality with NumberFormat
class, as I need to have grouping size based on Country like 1,2345,6789 for China, 1,234,567 for Canada or 1,23,450 for India.
I've tried looking for solutions but the solutions are based on DecimalForamt
. Is there any way we can use NumberFormat
to resolve this challenge?
Asked
Active
Viewed 139 times
0

Majid Roustaei
- 1,556
- 1
- 20
- 39

Moosa Naqvi
- 1
- 1
-
I don't think it is possible. Have a look at: https://stackoverflow.com/questions/5379231/displaying-currency-in-indian-numbering-format and also: https://stackoverflow.com/questions/34852803/format-currency-in-indian-numbering-format-without-symbol-in-java – Abra Sep 21 '20 at 18:49
1 Answers
0
DecimalFormat does not allow variable grouping size.
For variable grouping size, use Icu4J's DecimalFormat
com.ibm.icu.text.DecimalFormatSymbols dfs = new com.ibm.icu.text.DecimalFormatSymbols();
dfs.setGroupingSeparator(' ');
com.ibm.icu.text.DecimalFormat df = new com.ibm.icu.text.DecimalFormat("0,00,000", dfs); // indian numbering system
String s1 = df.format(500000); // 5,00,000
String s2 = df.format(121212123); // 12,12,12,123
String s3 = df.format(new com.ibm.icu.math.BigDecimal("67890000000000")); // 6,78,90,00,00,00,000

Mihai Pasca
- 54
- 5
-
-
NumberFormat is superclass of DecimalFormat. It does not support variable grouping size. Use the Icu4J library. – Mihai Pasca Sep 21 '20 at 18:58