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;
Share:
1,627
Izac Tan Ping Ping
Author by

Izac Tan Ping Ping

Updated on December 13, 2022

Comments

  • Izac Tan Ping Ping
    Izac Tan Ping Ping over 1 year

    How do I round down number 10999 to 10000?

  • jamesdlin
    jamesdlin over 4 years
    Note 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.