Shankar
Shankar

Reputation: 8957

Format double number using DecimalFormat

I am trying to format a double number using DecimalFormat class.

I hope this is printing based on Locale.

Code:

DecimalFormat df = new DecimalFormat("#####,###,###.00");
String result = df.format(99999999999.99);
System.out.println(result);

Actual output:

99,999,999,999.99

Expected Output:

99999,999,999.99

Upvotes: 1

Views: 219

Answers (2)

Sowanth
Sowanth

Reputation: 51

Hi Discover Shankar Bro, Kindly refer the below link and also try to use String Interpolation And Replacement.

http://tutorials.jenkov.com/java-internationalization/decimalformat.html

Upvotes: 0

john16384
john16384

Reputation: 8044

This is not supported, and you could have read this in the javadocs.

The grouping separator is commonly used for thousands, but in some countries it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".

Upvotes: 2

Related Questions