Number - potatoscript/javascript GitHub Wiki
Number
Number()
- Converts the object argument to a number that represents the object's value. home
If the value cannot be converted to a legal number, NaN is returned.
var n1 = true; Number(n1) => 1
var n2 = false; Number(n2) => 0
var n3 = new Date(); Number(n3) => 17171717171788 //returns the number of milliseconds since midnight January 1, 1970 UTC.
var n4 = "123"; Number(n4) => 123
var n5 = "abc"; Number(n5) => NaN``
ceil()
- Rounds a number UPWARDS to the nearest integer, and returns the result. If the passed argument is an integer, the value will not be rounded.home
Math.ceil()192.16) => 192.2
round()
- rounds a number to the nearest integer.home
Math.round(2.49); => 2 //will rounded down to 2
Math.round(2.5; => 3 //will rounded up to 3
String-To-Integer
var str = "2,222";
str.replace(",",""); => 2222
- parseInt() function parses a string and returns an integer.
var str = "2,222";
parseInt(str); => 2222
- parseFloat() function parses a string and returns a floating point number.
var str = "2,222.22";
parseFloat(str); => 2222.22
parseFloat(str).toFixed(1); => 222.2