我想要四舍五入双倍。
Double x = 5.56753;
x.toStringAsFixed(2);
当我输入这个时,它给出 5.57000。
但我想得到5.57。我怎样才能得到它?
有num
类包含函数round():
Num https://api.dartlang.org/stable/2.4.0/dart-core/num-class.html
double numberToRound = 5.56753;
print(numberToRound.round());
//prints 6
如果你想要小数
double n = num.parse(numberToRound.toStringAsFixed(2));
print(n);
//prints 5.57
查看评论建议 http://stackoverflow.com/a/66840734/3002719
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)