Created
December 7, 2009 00:22
-
-
Save r/250509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment