Skip to content

Instantly share code, notes, and snippets.

@gdotdesign
Created April 2, 2011 10:08
Show Gist options
  • Save gdotdesign/899368 to your computer and use it in GitHub Desktop.
Save gdotdesign/899368 to your computer and use it in GitHub Desktop.
Parses a string as a mathematical expression. Replaces percentages based on a number.
Number.eval("200%-140%-700",1280)
// result 68
Number.eval = (string,size) ->
Number.from(eval(String.from(string).replace /(\d*)\%/g, (match,str) ->
(Number.from(str)/100)*size
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment