Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round a number up in Flutter?

Tags:

flutter

dart

How can a number be rounded up to the nearest whole number in Flutter?

  • 0.1 => 1
  • 1.5 => 2
  • -0.1 => -1

The Num round methods rounds to the nearest integer. How can one always round up?

like image 486
Ray Li Avatar asked Jul 18 '20 19:07

Ray Li


1 Answers

You can use the .ceil() method to achieve what you want.

Example:

print(-0.1.ceil()); => -1
print(1.5.ceil()); => 2
print(0.1.ceil()); => 1
like image 106
V.N Avatar answered Sep 20 '22 13:09

V.N