I am converting and comparing two string values using
if (parseInt(x)!=parseInt(y)) {
The problem is if values are x="9" and y="09" the test returns false.
How can I get fix this ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use this :
If you don’t precise the radix, “09” is parsed as octal (this gives 0).
MDN documentation about parseInt
Note that you shouldn’t even rely on this interpretation when working with octal representations :
Simply :