【问题标题】:Java DecimalFormat output with dot separator带点分隔符的 Java DecimalFormat 输出
【发布时间】:2016-04-30 20:45:38
【问题描述】:

我使用 Decimalformat 两个用这行代码得到两位小数

DecimalFormat df = new DecimalFormat("#0.00");

我的输出例如是这样的

568,99  
1090,33
12897,45
233567,77

如何将十进制格式设置为这样输出?

568,99  
1.090,33
12.897,45
233.567,77

Decimalformat 中的方法有没有办法做到这一点。 像这样的代码

 df.setMinimumFractionDigits(3);
 df.setMaximumFractionDigits(3);
 df.setMinimumIntegerDigits(1);

我从未扩展我对 DecimalFormat 的了解,这就是我问的原因。

  1. 这可能与十进制格式代码有关吗?怎么样?

  2. 有没有更好的办法?

【问题讨论】:

  • 使用适当的语言环境。
  • NumberFormat.getInstance(myLocale);
  • "Is this possible to do with the decimalformat code?" -- 请阅读 DecimalFormat API,它会明确告诉您,,您应该使用 NumberFormat。如果这听起来像是 RTFM 评论,我很抱歉,但在这种情况下,它直接解决了您的问题。
  • 感谢两位的回答。我通过链接找到了我想要的东西。

标签: java decimalformat


【解决方案1】:

我意识到这些点看起来不太好看。 例如看这里。

1.234.345,00

所以我用这一行改为空白空间......

DecimalFormat df = new DecimalFormat("###,###.00");

创造了这个

1 234 345,00

【讨论】:

    猜你喜欢
    • 2017-09-30
    • 1970-01-01
    • 2012-05-13
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    相关资源
    最近更新 更多