Skip to content

Instantly share code, notes, and snippets.

@rusllonrails
Created February 15, 2014 09:36
Show Gist options
  • Save rusllonrails/9016770 to your computer and use it in GitHub Desktop.
Save rusllonrails/9016770 to your computer and use it in GitHub Desktop.
JAVASCRIPT ROUND UP
app.round_up = (float, digits) ->
digits = (if not digits? then 2 else digits)
k = Math.pow(10, digits)
int = (float * k).toFixed(1)
rounded = Math.floor(int)
((rounded + ((if int - rounded < 0.5 then 0 else 1))) / k).toFixed 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment