Number object is a digit, and its construction method:
Copy Code code as follows:
var num = 10;
var num = new number ();//num = = 0
var num = new number (value);
Where value is a numeric value or a quantity that can be converted to a numeric value, such as
String ' 1002 '
But if it is ' M122 ', return nan
1, constants, properties
Max_value |
The maximum number that can be represented. 1.7976931348623157e+308 |
Min_value |
The smallest number that can be represented. 5e-324 |
NaN |
Not a numeric value. NaN |
Negative_infinity |
Negative infinity, which is returned when it overflows. -infinity |
Positive_infinity |
Positive infinity, which is returned when it overflows. Infinity |
2. The toString () method converts a Number object to a string and returns the result.
Numberobject.tostring (radix);
Radix optional. A rule that represents the cardinality of a number, making an integer between 2 ~ 36.
If this argument is omitted, cardinality 10 is used.
A string representation of a number. For example, when Radix is 2 o'clock, Numberobject is converted to a string represented by a binary value.
Cases:
Copy Code code as follows:
var num = 10;
document.write (num.tostring (2));
Output: 1010
Note: The TypeError exception is thrown when the object that calls the method is not number.
3. The toFixed () method may be rounded down to the number specified in the decimal places.
Numberobject.tofixed (num);
Num required. Specify the number of digits, which are values between 0 ~ 20, including 0 and 20, and some implementations can support a larger range of values.
If this argument is omitted, 0 is substituted.
return value:
Num 0-20 does not throw an exception, if num>20 can throw an exception.
Copy Code code as follows:
var num = new number (13.37);
document.write (num.tofixed (1))
Output: 13.4
4. The toexponential () method converts the value of an object into an exponential counting method.
This method is the legendary scientific notation.
Numberobject.toexponential (num)
Num required. The number of decimal places specified in the exponential notation is the value between 0 ~ 20, including 0 and 20, and some implementations can support a larger range of values.
If this argument is omitted, as many digits as possible are used.
Copy Code code as follows:
var num = new number (10000);
document.write (num.toexponential (1))
Output:
1.0e+4
The 0 after the decimal point represents only one decimal.
5. The toprecision () method converts an object's value beyond a specified number of digits to an exponential count method.
Toprecision (num), num is the specified number of digits, that is, more than the number of digits using exponential counting method
Cases:
Copy Code code as follows:
var num = 10000;
document.write (Num.toprecision (4) + ' <br> ');
document.write (Num.toprecision (8));
Output:
1.000e+4//1.000 a total of 4 digits
10000.000//10000.000 Total 8 digits
See more JavaScript syntax, you can focus on: JavaScript reference tutorial, JavaScript Code style guide, and I hope you will support the cloud-dwelling community.