Java编号格式
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java编号格式,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1180字,纯文字阅读大概需要2分钟。
内容图文
![Java编号格式](/upload/InfoBanner/zyjiaocheng/772/3015e2e43fe54f92aed02f6b394a866c.jpg)
参见英文答案 > DecimalFormat variable group size 2个
> How to change the decimal separator of DecimalFormat from comma to dot/point? 6个
使用以下代码格式化编号为234156.123的模式#,##,###.###格式化为234,156.123,但它应格式化为
2,34,156.123
小数位数按照模式,而小数点前的数字不按预期格式化.
编写的代码如下
String pattern = "#,##,###.###";
double number = 234156.123;
DecimalFormat decimalFormat = new DecimalFormat(pattern);
String format = decimalFormat.format(number);
System.out.println(format);
结果:
234,156.123
预期结果:
2,34,156.123
解决方法:
来自Alex的评论docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
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 “#,##,###,####” == “######,####” == “##,####,####”.
要以这种方式格式化,您需要编写自定义格式化程序.
内容总结
以上是互联网集市为您收集整理的Java编号格式全部内容,希望文章能够帮你解决Java编号格式所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。