number.toExponential( fractionDigits )メソッドは、Numberオブジェクトの数値を指数表記にした文字列を返すメソッド。引数「fractionDigits」に小数点以下の桁数を指定できる。
構文
number.toExponential( fractionDigits )
引数
- fractionDigits
- 小数点以下の桁数を指定する。
- 省略可能。詳しくは、Number.toExponential()のページへ。
戻り値
指数表記にした文字列。
サンプル
<script type="text/javascript">
var $numberObject = new Number( 12345 );
document.write( '$numberObject.toExponential( 0 ) = ' );
document.write( $numberObject.toExponential( 0 ) + '<br />' );
document.write( '$numberObject.toExponential( 1 ) = ' );
document.write( $numberObject.toExponential( 1 ) + '<br />' );
document.write( '$numberObject.toExponential( 2 ) = ' );
document.write( $numberObject.toExponential( 2 ) + '<br />' );
document.write( '$numberObject.toExponential( 3 ) = ' );
document.write( $numberObject.toExponential( 3 ) + '<br />' );
document.write( '$numberObject.toExponential( 4 ) = ' );
document.write( $numberObject.toExponential( 4 ) + '<br />' );
document.write( '$numberObject.toExponential( 5 ) = ' );
document.write( $numberObject.toExponential( 5 ) + '<br />' );
document.write( '$numberObject.toExponential( 6 ) = ' );
document.write( $numberObject.toExponential( 6 ) + '<br />' );
</script>
var $numberObject = new Number( 12345 );
document.write( '$numberObject.toExponential( 0 ) = ' );
document.write( $numberObject.toExponential( 0 ) + '<br />' );
document.write( '$numberObject.toExponential( 1 ) = ' );
document.write( $numberObject.toExponential( 1 ) + '<br />' );
document.write( '$numberObject.toExponential( 2 ) = ' );
document.write( $numberObject.toExponential( 2 ) + '<br />' );
document.write( '$numberObject.toExponential( 3 ) = ' );
document.write( $numberObject.toExponential( 3 ) + '<br />' );
document.write( '$numberObject.toExponential( 4 ) = ' );
document.write( $numberObject.toExponential( 4 ) + '<br />' );
document.write( '$numberObject.toExponential( 5 ) = ' );
document.write( $numberObject.toExponential( 5 ) + '<br />' );
document.write( '$numberObject.toExponential( 6 ) = ' );
document.write( $numberObject.toExponential( 6 ) + '<br />' );
</script>
↓↓↓出力結果↓↓↓