【问题标题】:Using Javascript parseInt returns a different value使用 Javascript parseInt 返回不同的值
【发布时间】:2022-12-02 17:22:25
【问题描述】:

I\'m not entirely sure why the string \"6145390195186705543\" is outputting 6145390195186705000, at first reading through the threads it may be the base radix but even tinkering around with that still gives me the same results, can anyone help explain because I do believe this is not a bug, but I\'m not entirely sure what\'s the explanation here.

  const digits = [6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3]
  const val1 = digits.join(\'\') // string \"6145390195186705543\"
  const test1 = Number(val1)  // outputs 6145390195186705000
  const test2 = parseInt(val1) // outputs 6145390195186705000
  • 6145390195186705543 > Number.MAX_SAFE_INTEGER is true

标签: javascript parseint


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2015-11-06
  • 2012-07-13
  • 2021-10-06
  • 2016-05-20
  • 2016-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多