Guest User

Untitled

a guest
Apr 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. def significant_figures(num)
  2. sn = num.to_s.sub(/e[-+]*\d+$/i, '') # remove the scientific notation
  3. sn = sn.sub(/0*$/, '') unless sn.include?('.') # remove any trailing zeros
  4. sn.sub('.', '').sub(/^[-+]?0*/, '').length # remove the sign, leading zeros
  5. end
Add Comment
Please, Sign In to add comment