Basic Javascript tutorial-data type (numerical Number) _ basic knowledge

Source: Internet
Author: User
This article describes the second of nine data types in javascript-Number, which is very simple to use. We recommend it to our friends here. In javascript, you do not need to specify whether it is an integer or a floating-point number.

The Code is as follows:


Var num1 = 80;
Var num2 = 55.51;
Var num3 =-34;
Var num4 = 9e5;
Document. write (num1 + "" + num2 + "" + num3 + "" + num4 );
// The running result is 80 55.51-34 900000.

The toExponential () function is used to convert a value into a scientific and technical display. For example:

The Code is as follows:


Document. write (num2.toExponential (9); // output 5.55000000e + 1

Convert the object attributes and object methods of the w3cschool Value

Number Object Attributes

Attribute description
Constructor returns a reference to the Number function that creates this object.
MAX_VALUE indicates the maximum number.
MIN_VALUE represents the smallest number.
NaN is a non-numeric value.
NEGATIVE_INFINITY is negative infinity. This value is returned when overflow occurs.
POSITIVE_INFINITY is positive infinity. This value is returned when overflow occurs.
Prototype enables you to add attributes and methods to an object.

Number object Method

Method description
ToString converts a number to a string and uses the specified base number.
ToLocaleString converts a number to a string in the local numeric format order.
ToFixed converts a number to a string, and the result has a specified number of digits after the decimal point.
ToExponential converts the object value into an exponential notation.
ToPrecision format the number to the specified length.
ValueOf returns the basic numeric value of A Number object.

The above is all about the values in the javascript data type. I hope you will like it.

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.