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

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -