JavaScript中parseFloat的第二个参数? [英] Second argument to parseFloat in JavaScript?

查看:144
本文介绍了JavaScript中parseFloat的第二个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此字体大小调整教程中:

In this font-size resizing tutorial:


快速简单的调整字体大小

Quick and easy font resizing

作者使用parseFloat和第二个参数,我在这里读到:

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


parseFloat()w / two args

应该指定所提供的数字字符串的基数,这样您可以提供它为'0x10',并通过将16作为第二个参数将其识别为HEX。

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.

这些人是否会感到困惑使用Java?

Are these guys getting confused with Java?

推荐答案

不,他们对 parseInt(),它可以取一个基数参数。另一方面, parseFloat()只接受小数。它可能只是为了保持一致性,因为您应该始终将基数参数传递给 parseInt(),因为它可以将 010 为八进制,给出 8 而不是正确的 10

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.

以下是对 parseFloat()的引用。 code> ,而不是 parseInt( )

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

这篇关于JavaScript中parseFloat的第二个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆