spacer
Yehuda Shiran October 17, 2001
Setting the Number of Decimal Digits
Tips: October 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Linux 2.6.26 Opens Up to Debugging
Borland Launches ALM Management Tools
Nominations Open for CEO Vision Awards
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 and up.

Another way to format a floating number is to multiply it by the proper power of 10, round it to an integer, and then divide it back to the same power of 10. In the above example, you would multiply 1234.56789 by 10,000, get 12345678.9, round it to 12345679, and then divide it by 10,000 to get 1234.5679. Try it.


People who read this tip also read these tips:

Look for similar tips by subject:



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
How to Create an Ajax Autocomplete Text Field: Part 10 · Adding Client Capabilities to Server Controls Using the ASP.NET AJAX Control Toolkit · JavaScript and HTML Tricks
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Palm's Treo Presses On (iPhone Who?) · Toshiba Extends Notebook Line with 5400 and 7200-RPM Drives · Epson Kicks Color Cost to the Curb