简体   繁体   English

如何在 DecimalFormat 中使用空格作为分组分隔符?

[英]How can I use white space as a grouping separator in DecimalFormat?

I working on a Google Chart.我在做一个谷歌图表。 The API uses the DecimalFormat (ICU4J 53.1) . API 使用DecimalFormat (ICU4J 53.1) I am aiming this format:我的目标是这种格式:

### ### meters

But I can't find it inside the documentation .但是我在文档中找不到它。 Is there a work around for it?有解决方法吗?

If you have access to the DecimalFormat object, you can adjust it as follows:如果您有权访问DecimalFormat对象,则可以按如下方式调整它:

DecimalFormatSymbols formatSymbols = format.getDecimalFormatSymbols();
formatSymbols.setGroupingSeparator(' ');
format.setDecimalFormatSymbols(formatSymbols);

If you only have access to the format string, then you cannot achieve your goal.如果您只能访问格式字符串,则无法实现目标。 The DecimalFormat class formats numbers according to the locale and the grouping separator is taken from that. DecimalFormat类根据区域设置格式化数字,并从中获取分组分隔符。

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

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