spacer
Yehuda Shiran March 17, 2000
IE5.5's Number Formatting
Tips: March 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

Until IE5.5, formatting numbers was a real challenge. We all used high mathematical functions such as Math.ceil and Math.pow to format numbers the way we wanted to. IE5.5 fixes this problem with three new methods of the Number prototype object:

  • toFixed(fractionDigits)
  • toExponential(fractionDigits)
  • toPrecision(precision)

The toFixed(fractionDigits) method formats a number with fractionDigits digits after the decimal place. Suppose:

x = 1234.56789
and you call alert(x.toFixed(4)), you'll get 1234.5679 in IE5.5.

The toExponential(fractionDigits) method formats a number with fractionDigits digits after the decimal place, in exponential notation. Suppose:
x = 1234.56789
and you call alert(x.toExponential(2)), you'll get 1.23e+3 in IE5.5.

The toPrecision(precision) method formats a number with total precision number of digits, in exponential notation if needed. Suppose:

x = 1234.56789
and you call alert(x.toPrecision(2)), you'll get 1.2e+3 in IE5.5 .

When you call alert(x.toPrecision(9)), you'll get 1234.56789 in IE5.5.

Exprience some of these functions by yourself in Column 59, IE 5.5: Formatting, URIs, and Stack Operations.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger