简体   繁体   English

使用DecimalFormat格式化双数

[英]Format double number using DecimalFormat

I am trying to format a double number using DecimalFormat class. 我正在尝试使用DecimalFormat类格式化双精度数字。

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

This is not supported, and you could have read this in the javadocs. 不支持此功能,您可能已经在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. 分组大小是分组字符之间的数字位数,例如100,000,000为3或1,0000,0000为4。 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 "#,##,###,####" == "######,####" == "##,####,####". 因此,“#,##,###,####” ==“ ######,####” ==“ ##,####,####”。

Hi Discover Shankar Bro, Kindly refer the below link and also try to use String Interpolation And Replacement. 嗨,发现Shankar Bro,请参考以下链接,并尝试使用字符串插值和替换。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM