Conversion of each numeral in JavaScript

Source: Internet
Author: User
Tags numeric value

Use the base schema of ToString to convert:

A =. (A. ()-)


A =. (A. ()-)


ECMAScript for the numeric type is described below:

The ToString () method of number type is special, and it has two modes, the default mode and the base mode . With the default mode, the ToString () method simply outputs a numeric value (whether integer, floating point, or scientific notation) with the corresponding string, as follows:

var iNum1 = 10;var iNum2 = 10.0;alert (inum1.tostring ());//output "ten" alert (inum2.tostring ());//Output "10"

Note: in the default mode, the ToString () method of number type returns a decimal representation of the numbers, regardless of what notation was originally used to declare numbers. Therefore, the output of a number declared in the form of eight hexadecimal literals is in decimal form.

The base mode of the ToString () method with the number type can be used with different base output numbers, such as the binary base is 2, the octal base is 8, and the hexadecimal base is 16.

base is just another addition to the cardinality to be converted, which is the parameter of the ToString () method:

var iNum = 10;alert (inum.tostring (2)),//output "1010" Alert (inum.tostring (8));//Output "A" alert (inum.tostring (16));//Output "A"

In the previous example, the number 10 was output in 3 different forms, namely binary form, octal form, and 16 binary form. HTML is a hexadecimal representation of each color, which is useful when working with numbers in HTML.

Note: calling ToString (10) on a number is the same as calling ToString (), and they return the decimal form of the number.


This article is from the "Woody Rose" blog, please be sure to keep this source http://muxiangqiangwei.blog.51cto.com/3832230/1956431

Conversion of each numeral in JavaScript

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.