Home > Web Front-end > JS Tutorial > JavaScript data type conversion (parseInt, parseFloat)_Basic knowledge

JavaScript data type conversion (parseInt, parseFloat)_Basic knowledge

WBOY
Release: 2016-05-16 18:22:40
Original
1514 people have browsed it

JavaScript has two data type conversion methods:

(1) Convert the entire value from one type to another data type (called basic data type conversion)

(2) Extract a value of another type from one value and complete the conversion work



Three methods of basic data type conversion:

1. Convert to character type: String(); Example: The result of String(678) is "678"
2. Convert to numeric type: Number(); Example: The result of Number("678") is 678
3. Convert to Boolean Type: Boolean(); Example: The result of Boolean("aaa") is true



Method to extract another type of value from one value:

1. Extract the integer from the string: parseInt(); Example: the result of parseInt("123zhang") is 123
2. Extract the floating point number from the string: parseFloat(); Example: parseFloat("0.55zhang" ) is 0.55
3. Execute a piece of javascript code represented by a string: eval(); Example: the result of zhang=eval("1 1") is zhang=2

Note: Number, The String function is a special function. In the JS engine, it will automatically determine whether to call it as a constructor or a normal call, so you can use the new keyword or call it directly as a function.

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