Created
July 7, 2010 22:08
-
-
Save heapwolf/467365 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
var Num = function(value, options) { | |
options = options || ["num"]; | |
for(var o in options) { | |
if(options[o] == "trunc") { // truncate towards zero | |
value=~~value; | |
} | |
if(options[o] == "num") { // string or boolean to number | |
value=+value; | |
} | |
if(options[o] == "int") { // string to number or truncate toward zero | |
value=value|0; | |
} | |
if(options[o] == "odd") { // is the number odd? | |
value=!!(value & 1); | |
} | |
if(options[o] == "negative" || o == "neg") { | |
value=-value; | |
} | |
} | |
return value; | |
}; | |
Num("200.23"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this explains what i'm talking about a little better...