How do I round a number down to the closest 10000 in Flutter?
1,627
You can use the following code:
int x = 10999;
int divisor = 10000;
int result = (x / divisor).floor() * divisor;
Or using integer divisoin:
int x = 10999;
int divisor = 10000;
int result = (x ~/ divisor) * divisor;
Author by
Izac Tan Ping Ping
Updated on December 13, 2022Comments
-
Izac Tan Ping Ping over 1 year
How do I round down number
10999
to10000
? -
jamesdlin over 4 yearsNote that the
floor()
approach will round toward negative infinity and the integer division approach will round toward zero. That won't matter for 10999, but it would matter if rounding negative numbers.