How to round a number in Dart

July 2, 2020 Linda Walker 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
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles

0
Would love your thoughts, please comment.x
()
x