# Numbers
# Properties & Methods (opens new window)
❗️Floating point numbers cannot represent all decimals precisely in binary. This can lead to unexpected results, such as 0.1 + 0.2 === 0.3
returning false
.
# Rounding
.toFixed(digits)
(opens new window)- formats a number using fixed-point.
- parameter is optional
Math.round()
(opens new window) -> rounded to the nearest integerMath.ceil()
(opens new window) -> will round the value up.Math.floor()
(opens new window) -> will round the value down.Math.pow
(opens new window)
# String to Number
.parseInt()
(opens new window)- Turns String to Integer - parseInt(„60SJKL68“) -> 60
.parseFloat()
(opens new window)- Turns String to Float
a = a * 1;
Number()
(opens new window)
# Random
.Math.random()
(opens new window)
returns a floating-point, pseudo-random number in the range 0 to less than 1
function random(min, max) {
return Math.floor(Math.random() * (max + 1 - min)) + min;
}
or
random(min, max) => Math.floor(Math.random() * (max + 1 - min)) + min;
# Other Number-Methods (opens new window)
Math.sqrt()
Math.pow()
(opens new window) -> returns thebase
to theexponent
powerInfinity
,-Infinity