JavaScript Number Object

Source: Internet
Author: User

1.JavaScript number Object

JavaScript has only one numeric type.

You can use it or you can write a number without using a decimal point.

1.1JavaScript Digital

JavaScript numbers can be used or written without using a decimal point:

var pi=3.14;    // Use decimal point var x=;       // do not use decimal points

The maximum or minimum number can be written by means of the scientific (exponential) notation:

var y=123e5;    // 12300000 var z=123e-5;   // 0.00123

1.2 All JavaScript numbers are 64-bit

JavaScript is not a type language. Unlike many other programming languages, JavaScript does not define different types of numbers, such as integers, short, long, floating point, and so on.

In JavaScript, numbers are not classified as integer types and floating-point types, and all numbers are made of floating-point types. JavaScript uses the 64-bit floating-point format defined by the IEEE754 standard to represent numbers, which can represent a maximum value of ±1.7976931348623157 x 10308 and a minimum of ±5 x 10-324

1.3 Accuracy

Integers (not using decimal or exponential notation) are up to 15 bits.

var 999999999999999;   // x is 999999999999999 var 9999999999999999;  // y is 10000000000000000

The maximum number of decimal digits is 17, but the floating-point operation is not always 100% accurate:

var 0.2+0.1//  output is 0.30000000000000004

1.4 Octal and hexadecimal

If the prefix is 0, JavaScript interprets numeric constants as octal numbers, and if the prefixes are 0 and "X", they are interpreted as hexadecimal numbers.

var 0377  var0xFF;

By default, JavaScript numbers are displayed in decimal.

But you can use the ToString () method to output 16 binary, 8 binary, and 2 binary.

var mynumber=; mynumber.tostring (+);   // returnto Mynumber.tostring (8);    // returnto Mynumber.tostring (2);    // back to 10000000

1.5 Infinity (Infinity)

When the result of a numeric operation exceeds the upper limit (overflow) of the number that JavaScript can represent, the result is a special infinity (infinity) value, expressed as infinity in JavaScript. Similarly, when the value of a negative number exceeds the range of negative numbers that JavaScript can represent, the result is negative infinity, represented by-infinity in JavaScript. The behavior characteristics of infinite values are consistent with what we expect: based on their addition, subtraction, multiplication, and divide operations, or infinity (and, of course, their positive and negative numbers).

mynumber=2;  while (mynumber!=Infinity) {    mynumber//  repeat calculation until MyNumber equals Infinity}

Dividing by 0 also produces infinity:

var 2/0; var y =-2/0;

1.6NaN-Non-numeric value

The NaN property is a special value that represents a non-numeric value. This property is used to indicate that a value is not a number. You can set the number object to this value to indicate that it is not a numeric value.

You can use the IsNaN () global function to determine whether a value is a NaN value.

var  + " Apple "  //  returns Truevar"  +" // returns false

Divide by 0 is infinity, Infinity is a number:

var  + 0  //  return False

1.7 numbers can be numbers or objects

Numbers can be initialized with private data, just like x = 123;

JavaScript numeric object initialization data, var y = new number (123);

var 123 ; var New Number (123); typeof // return number typeof // return Object
var 123 ;               var New Number (123// is false because x is a digit and Y is an object

1.8 Numeric Properties

    • Max_value
    • Min_value
    • Negative_infinity
    • Positive_infinity
    • NaN
    • Prototype
    • Constructor

1.9 Digital methods

    • Toexponential ()
    • ToFixed ()
    • Toprecision ()
    • ToString ()
    • ValueOf ()

JavaScript Number Object

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.