Javascript Numeric Formatting
CSGNetwork FREE Source Code, Javascript Source, and Code Snippets!
CSGNetwork Custom Search
     Bookmark and Share
Top Free Apps

Right click this window and select "view source" in order to copy the source for this script.

Javascript Numeric Formatting Methods

Utilities for formatting numerical output in a human-friendly style. The ToFmt JavaScript object shown here and its associated methods enable numbers to be output as floating point values or powers of 10 with a specified width and number of figures after the decimal point, integer values, or to attach a leading zero to single digit numbers. The object and methods are included in the section of this document with a link to a more complete description.


Check these examples to see how to use the formatting functions and as a test to see if they function correctly on your browser; tested in most modern browsers.


To insert leading zero for integers 0-9. No change will take place for integers > 9.
Enter a postive integer: Result:


Tests for the fmtF(w,d),fmtE(w,d), and fmtI(w) functions, where w is the width of the field and d is the number of figures after the decimal point. The result is rounded either up or down to be correct to the number of digits requested. The result is aligned to the right of the field. The default padding character is a space " ".

Enter a floating point number (e.g. -234.856454):

Javascript Numeric Formatting

View the source...

This script formats field entry if it is numeric.

Bookmark and Share
Registered® Trademark™ and Copyrightę 1973 - CSG, Computer Support Group, Inc. and CSGNetwork.Com All Rights Reserved