Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created July 7, 2010 22:08
Show Gist options
  • Save heapwolf/467365 to your computer and use it in GitHub Desktop.
Save heapwolf/467365 to your computer and use it in GitHub Desktop.
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");
@heapwolf
Copy link
Author

heapwolf commented Jul 7, 2010

this explains what i'm talking about a little better...

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