如何在Flutter中的decimalPattern中设置maximumFractionDigits? [英] How to set the maximumFractionDigits in a decimalPattern in Flutter?

查看:321
本文介绍了如何在Flutter中的decimalPattern中设置maximumFractionDigits?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于用户区域设置,我显示小数,例如:
1234.567将位于:

Based on the user-locale I show decimals, for example: 1234.567 will be in:


  • 美国:1,234.567

  • NL:1.234,567

因此,我使用:
NumberFormat.decimalPattern(locale .toString())。format(1234.567)

那很好:)

但是现在我想设置最大的糖饼。
有一个 maximumFractionDigits ,但是如何应用一个?

But now I want to set the max-digets. There is a maximumFractionDigits, but how to apply this one?

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

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

On the currency it works like this: NumberFormat.currency(locale: locale.toString(), decimalDigits: 3).format(1234567)

推荐答案

来自另一个问题:

var forFractions = new NumberFormat();

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

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

print(format(15.501234));

因此,创建格式并设置maximumFractionDigits属性,然后执行格式。

So, create your format and set the maximumFractionDigits attribute then execute the format.

这篇关于如何在Flutter中的decimalPattern中设置maximumFractionDigits?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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