【问题标题】:Why don't work correct (parseInt) for convert string to int? [duplicate]为什么不能正确(parseInt)将字符串转换为int? [复制]
【发布时间】:2012-08-26 08:13:36
【问题描述】:

可能重复:
Why does parseInt(“09”) return 0 but parseInt(“07”) return 7?

我有一个类似 (10) | 的字符串(01)

我想转换为 int。

我用这个代码

parseInt("10") ----> 10
parseInt("07") ----> 7

但是当我将此代码用于 (08) 时,它会转换为 (0)

【问题讨论】:

  • 当你问它是重复的时候你怎么看不到?你看过方框中的其他问题了吗?
  • Exu,我搜索了很多但没有找到这个:(

标签: javascript asp.net


【解决方案1】:

If a string begins with 0 the default radix is 8.

尝试明确指定基数:

parseInt("08", 10)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-26
    • 2021-06-13
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 2013-11-12
    • 2014-03-18
    相关资源
    最近更新 更多