JavaScript DHTML/Javascript Objects/Number

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

Convert a Number to a Exponential format

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



Convert a number to a precision

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



Fix a number

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



Number.MAX_VALUE

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



Number.MIN_VALUE

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



Number.NEGATIVE_INFINITY

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



Number.POSITIVE_INFINITY

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



Number.toExponential()

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



Number.toFixed()

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



Number.toPrecision()

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