Number.parseFloat()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
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()
を参照してください。
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-number.parsefloat |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
parseFloat |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.