【问题标题】:Addition some float number and show the result with space separator and coma as decimal separator [closed]添加一些浮点数并使用空格分隔符和逗号作为小数分隔符显示结果[关闭]
【发布时间】:2016-08-06 21:55:57
【问题描述】:

您好,我有一个问题,我想添加一些浮点数并使用空格分隔符和逗号作为小数部分显示结果,例如 1 033 010,13

请问我该怎么做?

【问题讨论】:

标签: java android textview decimalformat


【解决方案1】:

你可以这样做:

System.out.println(NumberFormat.getNumberInstance(Locale.US)
    .format(1234567890.55).replaceAll(","," ").replace(".",","));

【讨论】:

  • 对我来说没问题。谢谢。
【解决方案2】:

查看NumberFormat,例如:

System.out.println(NumberFormat.getNumberInstance(Locale.US).format(1234567890))

1,234,567,890

您当然需要将Locale.US 更改为您的。

编辑

如果没有标准格式支持您想要的,请自定义!

Float.parseFloat("1234567890")

现在你有一个字符串...使用StringBuilder

某种类型的循环来扫描您的所有 " ""," 指标

numstr.insert(index, " ")numstr.insert(index, ",")

返回字符串numstr.toString()

【讨论】:

  • 不好,需要这样的结果 10 000 000,34
  • 如果要自定义到所有标准格式都不支持它,那么您需要制作自己的函数来自己更改它。
猜你喜欢
  • 2017-09-30
  • 1970-01-01
  • 2015-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-25
  • 2013-07-20
  • 1970-01-01
相关资源
最近更新 更多