Non vedo alcun modo per arrotondare un numero in Dart?Dove si trova Math.round() in Dart?
import 'dart:math';
main() {
print(Math.round(5.5)); // Error!
}
http://api.dartlang.org/docs/bleeding_edge/dart_math.html
Non vedo alcun modo per arrotondare un numero in Dart?Dove si trova Math.round() in Dart?
import 'dart:math';
main() {
print(Math.round(5.5)); // Error!
}
http://api.dartlang.org/docs/bleeding_edge/dart_math.html
Sì, c'è un modo per farlo. La classe num
ha un metodo chiamato round()
:
var foo = 6.28;
print(foo.round()); // 6
var bar = -6.5;
print(bar.round()); // -7
In Dart, tutto è un oggetto. Così, quando si dichiara una num, per esempio, si può arrotondare attraverso il round method from the num class, il seguente codice sarebbe stampare 6
num foo = 5.6;
print(foo.round()); //prints 6
Nel tuo caso, si potrebbe fare:
main() {
print((5.5).round());
}