How to round a number in Dart

Last updated on July 2, 2020 The Shadow Loading... Post a comment

In order to round numbers in Dart, just use the round() method.

Example:

void main() {
  var x = 10.3333;
  print(x.round()); 
  
  var y = -1.45;
  print(y.round());
  
  var z = 4.55;
  print(z.round());
}

Output:

10
-1
5

Related Articles

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x