Home > Web Front-end > JS Tutorial > Convert String to number in js for comparison_javascript tips

Convert String to number in js for comparison_javascript tips

WBOY
Release: 2016-05-16 16:42:18
Original
1188 people have browsed it

Comparing strings without conversion will result in a headache

If you were not careful when writing, you would not convert it, and then use it for rough testing,

1<2

Yes, that’s it

Then

5.002>21.003

Weird results occurred

When the data type is not converted to judge >, <, the system compares the unicode encoded value, and any result may occur

043db92cc39febd2bcf68102517ac513

or

str1*1>str2*1

When comparing data in js, don’t forget to convert types!

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