Dart中的Math.round()在哪里? [英] Where is Math.round() in Dart?

查看:122
本文介绍了Dart中的Math.round()在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不到任何在Dart中舍入数字的方法吗?

I don't see any way to round a number in Dart?

import 'dart:math';

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

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

推荐答案

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

Yes, there is a way to do this. The num class has a method called round():

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

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

这篇关于Dart中的Math.round()在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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