JavaScript入門講座

Home > Numberオブジェクト > toExponentialメソッド

toExponentialメソッド

toExponentialメソッドは数値を指数形式に変換する。

書式toExponential(桁数)
戻り値指数形式に変換した数値を返す
引数桁数 小数点以下の桁数を数値で設定する
使用例数値を指数形式に変換する。

    var num = 1.24577;

    //1.2e+0
    document.write('1:' , num.toExponential(1) , '<br />');
    //1.25e+0
    document.write('2:' , num.toExponential(2) , '<br />');
    //1.246e+0
    document.write('3:' , num.toExponential(3) , '<br />');
    //1.2458e+0
    document.write('4:' , num.toExponential(4) , '<br />');
    //1.24577e+0
    document.write('5:' , num.toExponential(5));
関連メソッド説明
toStringN進数の値に変換(Nは2~36)
toFixed小数点第N位で四捨五入
toPrecision指数桁数に変換