IEEE754 format is used to represent integer and floating point values.
Floating point value: This value must contain a decimal point, and there must be at least one number after the decimal point. Floating point values require twice the memory space as much as the integer value. The highest accuracy is 17 as a decimal, but its accuracy is far less than that of integers when performing arithmetic operations.
Various numerical types: decimal, octal (invalid in strict mode), hexadecimal
The first bit of the octal literal must be 0, followed by the octal number sequence (0~7). If the numeric value in the literal value is out of range, the leading 0 will be ignored and the subsequent numeric value will be parsed as a decimal number
070//56079//79
The first two digits of the hexadecimal literal must be 0x followed by the hexadecimal digits (0~9 and A~F). The letters A~F can be sized or lowercase
0xA//10
When performing arithmetic calculations, all values expressed in octal and hexadecimal will eventually be converted to decimal values
Value range:
If a value outside the javascript value range is obtained in the result of a calculation, then this value will be converted to a special Infinity value, which cannot participate in the next calculation because Infinity is a value that cannot participate in the calculation. If this number is positive, it is converted to Infinity (positive infinite), and if this number is negative, it is converted to -Infinity (negative infinite).
-10/0//-Infinity10/0//Infinity
isInfinite() determines whether a number is finite.
var result = Number.MAX_VALUE + Number.MAX_VALUEconsole.log(isFinity(result));//false
NaN
console.log(NaN === NaN)//false0/0//NaN
isNaN: Receive a parameter, and will try to convert this value into a numeric value, returning a Boolean value
console.log(isNaN('10'));//falseconsole.log(isNaN('bb'));//trueNumerical conversion
There are 3 functions that can convert non-numeric values into numeric values
Number(): Used for any numerical type.
1.null
Number(null)//0undefinedNumber(undefined)//NaN
2. Boolean value
Number(true)//1Number(false)//0
3. String
Number('bb')//NaN, non-numeric character Number('123')//123, numeric character Number('')//0, empty string4. Object
If it is an object, call the valueOf() method of the object, and then convert the returned value according to the above rules. If the result of the conversion is NaN, the object's toString() method is called, and the returned string value is converted again according to the previous rules.
5.parseInt()/parseFloat(): Used to convert a string to a numeric value.
parseInt(): start parsing from the first string until it is parsed to non-numeric characters. Two parameters can be accepted. The second parameter represents a different binary and is converted to a decimal number by default.
parseInt('')//NaN, empty string parseInt(22.4)//22parseInt('12bu')//12parseInt('10',2)//2parseInt('10',8)//8parseFloat(): start parsing from the first string, the first decimal point is valid, ignore the leading 0 and can only be converted to decimal values. parseFloat('')//NaNparseFloat('090')//90parseFloat('2.3.4')//2.3Summarize
Word:
Rounding-error
var x = .3 - .2 var y = .2 - .1 x == yx == .1 // => false .3 -.2 does not equal ./ y == .1 // => true .2 - .1 equals .1