rounding - In Ruby how do you round down a number to 2 significant digits -
For example,
If I have 24 9 8 9 54, I would return 24 million Need, is it possible?
Here's a greasy algorithm:
n = 24987654 n / (10 ** (n.to_s.size - 2)) * (10 ** (n.to_s.size - 2) => 24000000
Comments
Post a Comment