Second argument to parseFloat in JavaScript?

后端 未结 2 423
鱼传尺愫
鱼传尺愫 2020-12-20 12:15

In this font-size resizing tutorial:

Quick and easy font resizing

the author uses parseFloat with a second argument, which I rea

相关标签:
2条回答
  • 2020-12-20 12:49

    No, they're getting confused with parseInt(), which can take a radix parameter. parseFloat(), on the other hand, only accepts decimals. It might just be for consistency, as you should always pass a radix parameter to parseInt() because it can treat numbers like 010 as octal, giving 8 rather than the correct 10.

    Here's the reference for parseFloat(), versus parseInt().

    0 讨论(0)
  • 2020-12-20 13:04

    parseFloat can accept numbers other than decimal.

    console.log(parseFloat(010)) // 8

    0 讨论(0)
提交回复
热议问题