gpt4 book ai didi

dart - Dart 中的 Math.round() 在哪里?

转载 作者:行者123 更新时间:2023-12-03 00:29:15 26 4
gpt4 key购买 nike

我在 Dart 中看不到任何对数字进行四舍五入的方法?

import 'dart:math';

main() {
print(Math.round(5.5)); // Error!
}

http://api.dartlang.org/docs/bleeding_edge/dart_math.html

最佳答案

是的,有一种方法可以做到这一点。 num类有一个名为 round() 的方法:

var foo = 6.28;
print(foo.round()); // 6

var bar = -6.5;
print(bar.round()); // -7

关于dart - Dart 中的 Math.round() 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13275824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com