Use the IEEE754 format to represent integer and floating-point values.
floating-point value: The value must contain a decimal point, and must have at least one digit after the decimal. A floating-point number requires a memory space that is twice times the value of an integer. The highest precision is 17 decimal, but it is far less accurate than an integer in arithmetic operations.
various numeric types: decimal, octal (invalid in strict mode), Hex
The first digit of the octal literal must be 0, followed by the octal number sequence (0~7). If the value in the literal is out of range, the leading 0 is ignored and the following number is parsed as a decimal number
The first two digits of hexadecimal literals must be 0x, followed by hexadecimal digits (0~9 and a~f). Where the letter a~f can be size or lowercase
In arithmetic calculations, all values in eight and hexadecimal will eventually be converted to decimal values
Range of values:
If a value in the result of a calculation is obtained that exceeds the range of JavaScript values, the value is converted to a special infinity value that cannot participate in the next calculation because infinity is the number that cannot participate in the calculation. If the number is positive, it is converted to Infinity (positive infinity), and if the number is negative, it is converted to-infinity (negative infinity).
-10/0//-infinity
10/0//infinity
Isinfinite () Determines whether a number is poor.
var result = Number.MAX_VALUE + number.max_value
console.log (isfinity);//false
NaN
Console.log (nan = = nan)//false
0/0//nan
isNaN: Receives a parameter, attempts to convert this value to numeric value, returns a Boolean
Console.log (' isNaN ');//false
Console.log (isNaN (' BB '));//true
numeric conversions
There are 3 functions that can convert a Non-numeric value to a numeric value
Number (): Used with any numeric type.
1.null
Number (null)//0
undefined number
(undefined)//nan
2. Boolean value
Number (true)//1 number
(false)//0
3. String
Number (' BB ')//nan, non-numeric character number
(' 123 ')//123, numeric character numbers
(')//0, empty string
4. The object
if it is an object, the valueof () method of the object is invoked, and then the returned value is converted according to the rules above. If the result of the conversion is Nan, the object's ToString () method is called, and then the string value returned by the previous rule transformation is again followed.
5.parseInt ()/parsefloat (): Used to convert a string to a numeric value.
parseint (): Resolves from the first string until it resolves to a non-numeric character, accepts two arguments, the second parameter represents a different feed, and the default is converted to decimal numbers.
parseint (')//nan, empty string
parseint (22.4)//22 parseint (
' 12bu ')//12 parseint (' 2 ')//2 parseint
(' 8)//8
parsefloat (): Parsing begins with the first string, the first decimal point is valid, the leading 0 is ignored, and can only be converted to decimal values.
parsefloat (')//nan
parsefloat (' 090 ')//90 parsefloat
(' 2.3.4 ')//2.3
Summarize
- does not differentiate between integer values and floating-point numbers, and all digits in JavaScript are identified with 64-bit floating-point numbers (IEEE 754).
- Like a Java programmer familiar with the double type
- Values range from ±1.7976931348623157x10 308 to ±5x10−324
-
Text:
- Integer
- Floating point representation
- Math class
- Method
- POW//exponentiation
- round //rounding
- ceil //Up rounding
- floor //down rounding
- ABS //Absolute value
- Max //MAX value
- min //Most small value
- sqrt
- Log
- Exp
- ACOs
- Asin
- Atan
- Atan2
- Random
- Sin
- Cos
- Constant
- Pi
- E
- LN2
- LN10
- Log2e
- log10e
- Pi
- Sqrt1_2
- SQRT2
- Infinite value
- Positive Infinity
- Infinity//RW
- Number.POSITIVE_INFINITY//R
- 1/0
- Number.MAX_VALUE + 1
- Negative infinity
- Number.negative_infinity//RW
- -intifinty//r
- -1/0
- -number.max_value-1
- NaN
- Not equal to any value including its own.
- NaN//RW
- Number.NaN//r
- 0/0//The result is Nan
- Zero
- Number.min_value/2
- -number.min_value/2
- -1/infinity
- -0
Rounding-error
var x =. 3-. 2
var y =. 2-. 1
x = = y
x = = 1//=> false. 3-.2 is not equal to./
y = = 1//=> true. 2-. 1 equals. 1