Where is Math.round() in Dart?
UPDATE March 2021:
The round()
method has moved to https://api.dart.dev/stable/2.12.2/dart-core/num/round.html. All the above links are wrong.
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
In Dart, everything is an object. So, when you declare a num, for example, you can round it through the round method from the num class, the following code would print 6
num foo = 5.6;
print(foo.round()); //prints 6
In your case, you could do:
main() {
print((5.5).round());
}
This equation will help you
int a = 500;
int b = 250;
int c;
c = a ~/ b;