Javascript-number-toexponential

提供:Dev Guides
移動先:案内検索

JavaScript番号-toExponential()

説明

このメソッドは、指数表記の number オブジェクトを表す文字列を返します。

構文

その構文は次のとおりです-

number.toExponential( [fractionDigits] )

パラメータの詳細

*fractionDigits* -小数点以下の桁数を指定する整数。 デフォルトでは、番号を指定するのに必要な数の数字が使用されます。

戻り値

小数点の前に1桁の指数表記のNumberオブジェクトを表す文字列。小数点の後に fractionDigits 桁に丸められます。 fractionDigits 引数を省略した場合、小数点以下の桁数は、デフォルトで値を一意に表すために必要な桁数になります。

次の例を試してください。

<html>
   <head>
      <title>Javascript Method toExponential()</title>
   </head>

   <body>
      <script type = "text/javascript">
         var num = 77.1234;
         var val = num.toExponential();
         document.write("num.toExponential() is : " + val );
         document.write("<br/>");

         val = num.toExponential(4);
         document.write("num.toExponential(4) is : " + val );
         document.write("<br/>");

         val = num.toExponential(2);
         document.write("num.toExponential(2) is : " + val);
         document.write("<br/>");

         val = 77.1234.toExponential();
         document.write("77.1234.toExponential()is : " + val );
         document.write("<br/>");

         val = 77.1234.toExponential();
         document.write("77 .toExponential() is : " + val);
      </script>
   </body>
</html>

出力

num.toExponential() is : 7.71234e+1
num.toExponential(4) is : 7.7123e+1
num.toExponential(2) is : 7.71e+1
77.1234.toExponential()is:7.71234e+1
77 .toExponential() is : 7.71234e+1