Javascript number object

Source: Internet
Author: User
Tags binary to decimal decimal to binary
ArticleDirectory
    • Number object Method
    • Number Object Attributes

Javascript has only one numeric type. It is represented as a 64-bit floating point number internally, the same as Java's double. Unlike most otherProgramming Language, It does not separate the integer type, so 1 and 1.0 are the same value. This provides great convenience, because it completely avoids short integer overflow. Everything you need to know is that it is a number. This avoids a lot of errors caused by the number type.

Number object Method

FF: Firefox, ie: Internet Explorer

>
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
Tosource () Representing the objectSource code 1.0 -
Valueof Returns the basic numeric value of A number object. 1.0 4.0
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
VaR isnumber = function (n) {return typeof n = 'number' & isfinite (n );}
 
Alert (0.1 + 0.2) = 0.3) // false

Obtain Random Number

 
Function getrandom (Min, max) {return math. Floor (math. Random () * (max-min + 1) + min ;}

There is a special value in Javascript called infinity. It represents a number too big
For JavaScript to handle. Infinity is indeed a number, as typing typeof infinity
In the console will confrm. You can also quickly check that a number with 308 Zeros
Is OK, but 309 Zeros is too much. To be precise, the biggest number javascript can
Handle is 1.7976931348623157e + 308 while the smallest is 5e-324.

Convert JavaScript decimal to binary, convert binary to decimal

 var random = (function () {var seed = 49734321; return function () {// Robert Jenkins '32 bit integer Hash function. seed = (seed + 0x7ed55d16) + (seed <12) & 0 xffffffff; seed = (seed ^ 0xc761c23c) ^ (seed >>> 19 )) & 0 xffffffff; seed = (seed + 0x165667b1) + (seed <5) & 0 xffffffff; seed = (seed + 0xd3a2646c) ^ (seed <9 )) & 0 xffffffff; seed = (seed + 0xfd7046c5) + (seed <3) & 0 xffffffff; seed = (seed ^ 0xb55a4f09) ^ (seed >>> 16) & 0 xffffffff; Return (Seed & 0 xfffffff)/0x10000000 ;}) (); console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () console. log (random () 

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.