我正在制作int计算器,但是这里有一些问题:使用此代码时,我得到的值不正确,这是无法预期的。
我使用了toString(),它将int返回到字符串。
041014.toString().padStart(6, "0").split('') // [ '0', '1', '6', '9', '0', '8' ]
"041014".toString().padStart(6, "0").split('') // [ '0', '4', '1', '0', '1', '4' ]
我想将其视为6个字符的字符串,但返回不正确的字符串。如何解决?
以零开头的数字是一个八进制,删除前导0。请注意,在严格模式下,不允许这样做。参见Why are Octal numeric literals not allowed in strict mode (and what is the workaround?)