JavaScript Reference/Javascript Methods/toPrecision

Материал из Web эксперт
Перейти к: навигация, поиск

"toPrecision()" Example

   <source lang="javascript">
   

<html> <body> <button onclick="var myNum = new Number(10000); alert(myNum.toPrecision(1));"> to Precision </button> </body> </html>


     </source>
   
  


"toPrecision()" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |Number | +----------------+--------------------------------------------------------------+

     </source>
   
  


"toPrecision()" Syntax Parameters and Note

   <source lang="javascript">

Note: Converts a number to exponential notation if it contains more digits than specified parameter.

Syntax:

numberName.toPrecision(param1) Parameters:

   param1   Required; minimum number of digits to convert to exponential notation. 
   
     
     </source>