Numbers
JavaScript numbers are always stored as double precision (64-bit) floating point numbers.
There is no distinction between integers and decimals.
var myInteger = 20;
var myDecimal = 5.55;
Check if a value is a number or not
isNumber()
NaN()
parseFloat()
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);
Number Function
The Number() function converts the object argument to a number that represents the objects value.
If the argument is a Date object, this function returns the number of milliseconds since midnight 1 Jan 1970 UTC.
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopNext