JavaScript DHTML/Javascript Objects/Number

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

Convert a Number to a Exponential format

   <source lang="html4strict">

   

<html> <body> <button onclick="var myNum = new Number(100); alert(myNum.toExponential(1));"> Number toExponential </button> </body> </html>


 </source>
   
  


Convert a number to a precision

   <source lang="html4strict">

   

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


 </source>
   
  


Fix a number

   <source lang="html4strict">

   

<html> <body> <button onclick="var myNum = new Number(100.22); alert(myNum.toFixed(1));"> Number toFixed </button> </body> </html>


 </source>
   
  


Number.MAX_VALUE

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> document.writeln(Number.MAX_VALUE + "
"); </script> </body> </html>


 </source>
   
  


Number.MIN_VALUE

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> document.writeln(Number.MIN_VALUE + "
"); </script> </body> </html>


 </source>
   
  


Number.NEGATIVE_INFINITY

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> document.writeln(Number.NEGATIVE_INFINITY + "
"); </script> </body> </html>


 </source>
   
  


Number.POSITIVE_INFINITY

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript">

   document.writeln(Number.POSITIVE_INFINITY + "
");

</script> </body> </html>


 </source>
   
  


Number.toExponential()

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> var newValue = new Number("31234123.8896"); document.writeln(newValue.toExponential(3) + "
"); </script> </body> </html>


 </source>
   
  


Number.toFixed()

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> var newValue = new Number("4.8896"); document.writeln(newValue.toFixed(6) + "
"); </script> </body> </html>


 </source>
   
  


Number.toPrecision()

   <source lang="html4strict">
 

<html> <head> <title>Number properties</title> </head> <body> <script type="text/javascript"> var newValue = new Number("4.8896"); document.writeln(newValue.toPrecision(3) + "
"); </script> </body> </html>


 </source>