如何在Flutter(Dart)中将一个数字四舍五入到小数点后一定的位数?

lzfw57am  于 2023-11-14  发布在  Flutter
关注(0)|答案(1)|浏览(258)

此问题在此处已有答案

How do you round a double in Dart to a given degree of precision AFTER the decimal point?(29个回答)
14天前关闭
例如,我如何在Flutter( dart )中将8.245四舍五入到8.25?我还没有找到一个有效的方法。任何意见都很感激,谢谢。

jxct1oxe

jxct1oxe1#

在这种情况下,可以使用toStringAsFixed
对于EX:-

(4321.12345678).toStringAsFixed(5);  // 4321.12346

字符串
欲了解更多信息,请访问https://api.dart.dev/stable/3.1.5/dart-core/num-class.html#id_toStringAsFixed

相关问题