Use DecimalFormat
for this problem.
double amount = 32690597;
//create pattern for decimal format
String pattern = "###,###";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
//change dot with comma
String formattedNumber = decimalFormat.format(amount).replace(".",",");
In detail Decimal Formatter keys ;
0 A digit - always displayed, even if number has less digits (then 0 is displayed)
# A digit, leading zeroes are omitted.
. Marks decimal separator
, Marks grouping separator (e.g. thousand separator)
E Marks separation of mantissa and exponent for exponential formats.
; Separates formats
- Marks the negative number prefix
% Multiplies by 100 and shows number as percentage
? Multiplies by 1000 and shows number as per mille
¤ Currency sign - replaced by the currency sign for the Locale. Also makes formatting use the monetary decimal separator instead of normal decimal separator. ¤¤ makes formatting use international monetary symbols.
X Marks a character to be used in number prefix or suffix
' Marks a quote around special characters in prefix or suffix of formatted number.
Some Examples with this ;
Pattern Number Formatted String
###.### 123.456 123.456
###.# 123.456 123.5
###,###.## 123456.789 123,456.79
000.### 9.95 009.95
##0.### 0.95 0.95