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 -

java - Reaching JTextField in a DocumentListener -

c# - Add Image in a stackpanel based on textbox input -