Skip to content

Instantly share code, notes, and snippets.

@rickclare
Created September 12, 2012 10:04
Show Gist options
  • Save rickclare/3705700 to your computer and use it in GitHub Desktop.
Save rickclare/3705700 to your computer and use it in GitHub Desktop.
Rounding Example
if res > 1
# round to nearest 0.5L
res = ( Math.round(res*2)/2 ).toFixed(1)
else
# round to nearest 0.05L
res = ( Math.round(res*20)/20 ).toFixed(2)
end
Copy link

ghost commented Sep 13, 2012

if res > 0.75

round to nearest 0.5L (e.g. 1, 1.5, 2.0 etc)

if res > 0.05 and < 0.75

round to nearest 0.05L (e.g. 0.05, 0.10, 0.15 etc.)

else
give # to two decimal places (e.g. 0.01, 0.02, 0.3 etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment