简体   繁体   English

JavaScript 中数字以零开头,不希望进行八进制转换

[英]Number Starts with Zero in JavaScript,Don't want for Octal Converstion

In JavaScript if the number starts with 0 it's getting converted as octal during manipulation.在 JavaScript 中,如果数字以0开头,则在操作过程中它会被转换为八进制

For example:例如:

var mobileNumber = 01000;// Collecting from User Input

then value of the mobileNumber is 512 during manipulation.那么在操作过程中 mobileNumber 的值为512

We have a custom class for mobile number processing, I should pass '01000' to that accessor method.我们有一个用于手机号码处理的自定义类,我应该将“01000”传递给该访问器方法。

Kindly suggest us solution for it.请建议我们解决它。

使用 parseInt 函数的第二个参数: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

parseInt('01000', 10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM