Home > Web Front-end > JS Tutorial > Display type conversion in JS

Display type conversion in JS

php中世界最好的语言
Release: 2018-03-16 15:08:51
Original
1862 people have browsed it

This time I will bring you the display type conversion in JS , what are the precautions for display type conversion in JS, the following is a practical case, let's take a look.

Number(), convert things into numeric types

Number('123');          //123Number('-123');         //-123Number('a');            //NaNNumber(true);           //1Number(null);           //0Number(undefined);      //NaNNumber(NaN);            //NaN
Copy after login

parseInt(string, radix), convert strings into integers in the corresponding base system

parseInt('10', 16);     //16parseInt('b', 16);      //11parseInt('b');          //NaNparseInt('3', 2);       //NaN,因为3不是二进制的parseInt(true);         //NaNparseInt('123abc');     //123parseInt('abc123');     //NaN
Copy after login

parseFloat(string, radix), convert the string into a floating point number in the corresponding base system

String(mix)
Copy after login

Convert things into string type, undefined and null can be converted into string form

String(null);           //"null"String(undefined);      //"undefined"
toString(radix)
Copy after login

Convert things into string types, undefined and null cannot be used, radix is ​​based on decimal and converted into the target base

var num = 100;
num.toString();     // "100"//注意,不能直接123.toString(),会报错
Copy after login

I believe you have mastered the method after reading the case in this article, please come for more exciting information Follow php Chinese websiteOther related articles!

Recommended reading:

Detailed explanation of h5 game development

##The use of Nodejs routing and controller

FTP file management

The above is the detailed content of Display type conversion in JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template