【问题标题】:How to set the maximumFractionDigits in a decimalPattern in Flutter?如何在 Flutter 的 decimalPattern 中设置 maximumFractionDigits?
【发布时间】:2020-08-27 09:56:10
【问题描述】:

根据用户区域设置,我显示小数,例如: 1234.567 将在:

  • 美国:1,234.567
  • 荷兰:1.234,567

为此我使用: NumberFormat.decimalPattern(locale.toString()).format(1234.567)

效果很好:)

但现在我想设置最大数字。 有一个maximumFractionDigits,但是这个怎么申请呢?

这个不行:NumberFormat.decimalPattern(locale.toString(), maximumFractionDigits: 2).format(1234.567)

在货币上,它的工作方式如下:NumberFormat.currency(locale: locale.toString(), decimalDigits: 3).format(1234567)

【问题讨论】:

  • 你能举一个期望输出的例子吗?

标签: flutter dart


【解决方案1】:

另一个问题:

var forFractions = new NumberFormat();

forFractions.minimumFractionDigits = 2;
forFractions.maximumFractionDigits = 2;

format(num n) => forFractions.format(n);

print(format(15.501234));

所以,创建您的格式并设置 maximumFractionDigits 属性,然后执行该格式。

【讨论】:

  • 谢谢!当然应该是这样的。只是补充。如果您想将语言环境添加到号码中,请将其初始化为:NumberFormat numberFormat = new NumberFormat.decimalPattern(locale.toString());
猜你喜欢
  • 1970-01-01
  • 2019-09-05
  • 2020-09-05
  • 2021-07-02
  • 2019-08-23
  • 2019-06-09
  • 2021-08-20
  • 2018-12-16
  • 1970-01-01
相关资源
最近更新 更多