I'm trying to think of a function in C that would satisfy the following conditions:
For example:
53 comes out as 60..
197 comes out as 200..
4937 comes out as 5000..
Is there a way to do this so that the requirement is satisfied regardless of the number of trailing zeroes?
For example, I understand how I could do it in any individual case. divide 53 by 10 then ceil(), multiply by 10,
but I would like one that can handle any value.
Opinions? Ideas?
Avoid string conversions and loops:
int num = ... // your number
int len = log10(num);
float div = pow(10, len);
int rounded = ceil(num / div) * div;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With