October 2006
Beginner to intermediate
352 pages
9h 33m
English
The Number object’s unique
methods have to do with conversion—to string, to
locale-specific string, to a given precision- or fixed-point
representation, and to exponential notation. The object also has four
constant numeric properties, directly accessible from the Number object.
Rather than list each Number
object’s methods and properties, Example 4-1
demonstrates how they work by calling each and printing out their
results and/or values.
Example 4-1. The Number object methods
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>The Number Object</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
//<![CDATA[
// Number properties
document.writeln(Number.MAX_VALUE + "<br />");
document.writeln(Number.MIN_VALUE + "<br />");
document.writeln(Number.NEGATIVE_INFINITY + "<br />");
document.writeln(Number.POSITIVE_INFINITY + "<br />");
// Number specific methods
var newValue = new Number("34.8896");
document.writeln(newValue.toExponential(3) + "<br />");
document.writeln(newValue.toPrecision(3) + "<br />");
document.writeln(newValue.toFixed(6) + "<br />");
//]]>
</script>
</body>
</html>Figure 4-1 shows the results of running this JavaScript application.

Figure 4-1. The Number object methods
In Example 4-1, two numeric ...
Read now
Unlock full access