Numbers


There is no distinction between integers and decimals.

var myInteger = 20; 
var myDecimal = 5.55;

1 == "1"     // true 
1 === "1" // false
100 + "25" // 10025
"text" + 1 // text 1

var v1 = 1   // integer 
var v2 = 2.5 // floating point
var v3 = 070 // integer (in octal, 0 prefix)
var v4 = 0xffff // integer (in hex, 0x prefix)
var v5 = 1.34e5 // scientific

All numbers are floating point
so decimal fractions are not exact.
standard operators +, -, *, /, %
parseFloat - converts a string to a number


number value Data Type



Number Object




Methods

toFixed(n) - returns the number to n decimal places


let number1 = parseInt("11 two 33"); 
let number2 = parseFloat("22 three 44");
let number3 = 11.234.toFixed(0);
let number4 = 100.6.toFixed(2);



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopNext