没有为DecimalFormat分组的分隔符char [英] no grouping separator char for DecimalFormat

查看:57
本文介绍了没有为DecimalFormat分组的分隔符char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DecimalFormat 使用','作为默认分组分隔符.

DecimalFormat uses ',' as the default grouping separator character.

告诉DecimalFormat我们不需要任何分组分隔符的正确方法是什么?我目前使用的是symbols.setGroupingSeparator('\ 0'),它似乎可以正常工作,但是看起来很丑.

What is the correct way to tell DecimalFormat that we don't want any grouping separator character? I currently use symbols.setGroupingSeparator('\0'), and it seems to work, but it looks ugly.

DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator('\0');

DecimalFormat df = new DecimalFormat();
df.setDecimalFormatSymbols(symbols);

ParsePosition pp = new ParsePosition(0);
Number result = df.parse("44,000.0", pp);   // this should fail, as I don't want any grouping separatator char.
if (pp.getIndex() != input.length())
   throw new Exception("invalid number: " + input, 0);

告诉DecimalFormat我们不需要任何分组分隔符char的正确方法是什么?

What is the correct way to tell DecimalFormat that we don't want any grouping separator char?

推荐答案

通过调用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆