Second argument to parseFloat in JavaScript?

*爱你&永不变心* 提交于 2019-12-30 16:26:24

问题


In this font-size resizing tutorial:

Quick and easy font resizing

the author uses parseFloat with a second argument, which I read here:

parseFloat() w/two args

Is supposed to specify the base of the supplied number-as-string, so that you can feed it '0x10' and have it recognized as HEX by putting 16 as the second argument.

The thing is, no browser I've tested seems to do this.

Are these guys getting confused with Java?


回答1:


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().



来源:https://stackoverflow.com/questions/8555649/second-argument-to-parsefloat-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!