HTML Dom tutorial 49-javascript number object

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.