pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat

pt src="/static/client/4585.458a2b03d77c78d5.js" type="module">

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Number.parseFloat()

基线 广泛可用

自 2015年9月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

Number.parseFloat() 静态方法解析参数并返回浮点数。如果无法从参数中解析出一个数字,则返回 NaN

尝试一下

function circumference(r) {
  if (Number.isNaN(Number.parseFloat(r))) {
    return 0;
  }
  return parseFloat(r) * 2.0 * Math.PI;
}

console.log(circumference("4.567abcdefgh"));
// Expected output: 28.695307297889173

console.log(circumference("abcdefgh"));
// Expected output: 0

语法

js
Number.parseFloat(string)

参数

string

要解析的值,会被强制转换为字符串。该参数开头的空白会被忽略。

返回值

由给定 string 解析得到的浮点数。

如果第一个非空白字符不能被转换为数字,则返回 NaN

示例

Number.parseFloat 与 parseFloat 对比

此方法与全局函数 parseFloat() 具有相同的功能:

js
Number.parseFloat === parseFloat; // true

其目的是全局的模块化。

有关更多详细信息和示例,请参见 parseFloat()

规范

规范
ECMAScript® 2027 Language Specification
# sec-number.parsefloat

浏览器兼容性

参见

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy