JavaScript

Number.prototype.toExponential() メソッド


編集:2023.01.25 by T.A.

[Edge]。→

Number を指数表記で表した文字列で返します。

構文
Number.toExponential([fractionDigits])
Number 数値を表す、オブジェクト、変数。→Number()
fractionDigits 省略可。小数点以下の桁数を表す数値。省略時は、その数を表すのに必要な桁で返されます。
戻り値

文字列、または NaN(Number の値が NaN だった場合)。

//Numberの指定
N=123.45;  //数値として。
D=N.toExponential();  //=[string]:1.2345e+2
N=Number("123.45");   //オブジェクトとして。
D=N.toExponential();  //=[string]:1.2345e+2
N="123.45";           //文字列として。
D=N.toExponential();  //エラー発生:N.toExponential is not a function
D=NaN.toExponential();  //=[string]:NaN
N=123;
D=N.toExponential();  //=[string]:1.23e+2
N=1;
D=N.toExponential();  //=[string]:1e+0
N=0;
D=N.toExponential();  //=[string]:0e+0

//fractionDigits
N=1;
D=N.toExponential(3);  //=[string]:1.000e+0
N=1.234567;
D=N.toExponential(3);  //=[string]:1.235e+0

Number()


テスト