spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column59


IE 5.5: Formatting, URIs, and Stack Operations

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Formatting Numbers

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 .

Next: How to format data according to local settings

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: March 14, 2000
Revised: April 26, 2000

URL: http://www.webreference.com/js/column59/2.html