问题描述
在控制台中执行一些随机表达式时,我发现
While executing some random expressions in console, I just found that
010 +
返回 8
(甚至011,0100 ..通过考虑八进制数系统返回结果)
010 + ""
returning 8
(even 011,0100.. are returning results by considering octal number system)
如果需要,我该怎么办?我想将数字 010
转换为字符串010
?不仅是 010
,而是针对每个相似的数字。我设法为这个找到了类似的解释。但这并没有解释如何将其转换为精确的字符串版本。
What would I have to do if I want to convert a number 010
to a string "010"
? Not only for 010
but for every similar numbers. I managed to find a kind of similar explanation for this here. But that is not explaining how to convert it into a exact string version.
推荐答案
在Javascript 010
是八进制文字,并在十进制文字中转换为8。事实上,你应该避免它,因为严格模式不允许使用它。
In Javascript 010
is octal literal and converts to 8 in decimal literal. In fact, you should avoid it, as strict mode disallows to use it.
除了解析函数体字符串之外,没有办法区分八进制和十进制表示法:)
There is no way to distinguish between octal and decimal notation other than parsing function body string :)
这篇关于如何将数字010转换为字符串“010”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!