Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def significant_figures(num)
- sn = num.to_s.sub(/e[-+]*\d+$/i, '') # remove the scientific notation
- sn = sn.sub(/0*$/, '') unless sn.include?('.') # remove any trailing zeros
- sn.sub('.', '').sub(/^[-+]?0*/, '').length # remove the sign, leading zeros
- end
Add Comment
Please, Sign In to add comment