HTML Dom tutorial 49-javascript number object
In JavaScript, numbers are a basic data type.
Javascript supports the number object, which is the packaging object of the original value.
When necessary, JavaScript will automatically convert between the original data and the object.
The constructor number () can be used directly as a conversion function instead of the new operator. When you call number () in this way, it will convert its parameter into a number, and then return the converted original value (or Nan ).
1: Number object Method
Method |
Description |
FF |
IE |
Tostring |
Converts a number to a string and uses the specified base number. |
1.0 |
4.0 |
Tolocalestring |
Converts a number to a string in the format of a local number. |
1.0 |
4.0 |
Tofixed |
Converts a number to a string. The result is a number of the specified digits after the decimal point. |
1.0 |
5.5 |
Toexponential |
Converts a number to a string and returns an exponential notation. the decimal point has a specified decimal number. |
1.0 |
5.5 |
Toprecision |
Converts a number to a string that contains a valid number of specified digits. The exponential or fixed-point counting method is used to determine the value of a number and the specified number of valid digits. |
1.0 |
5.5 |
Valueof |
Returns the basic numeric value of A number object. |
1.0 |
4.0 |
2: Number Object Attributes
Attribute |
Description |
FF |
IE |
Max_value |
The maximum number that can be expressed. |
1.0 |
4.0 |
Min_value |
The smallest number that can be expressed. |
1.0 |
4.0 |
Nan |
Non-numeric value. |
1.0 |
4.0 |
Negative_infinity |
Negative infinity. This value is returned when overflow occurs. |
1.0 |
4.0 |
Positive_infinity |
Positive infinity. This value is returned when overflow occurs. |
1.0 |
4.0 |
Note: The preceding five constants are the attributes of the constructor number (), rather than the attributes of a single number object.
For example, the max_value attribute is correct:
VaR big = number. max_value
However, this is incorrect:
VaR n = new number (2 );
VaR big = n. max_value