LANGUAGE ยป JAVASCRIPT
Number
Basic usage โ
javascript
mynum = 1000; // Decimal notation
mynum = 1e3; // Exponential notation (same as 1 * 10^3 = 1000)
mynum = 0xff; // Hexadecimal notation
mynum = 0b11111111; // Binary notationConvert from string โ
Both integer and float are Number.
javascript
Number.parseInt('10');
Number.parseFloat('3.1416');If the conversion fails, NaN is returned.
javascript
isNaN(myVar);Rounding โ
To the nearest integer:
javascript
Math.round(0.9);
// 1With the specified number of decimal places (string is returned):
javascript
3.78932.toFixed(2);
// '3.79'