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.
Examples
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.
fmt00
To insert leading zero for integers 0-9. No change will take
place for integers > 9.
fmtF(w,d),fmtE(w,d),fmtI(w)
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 " ".
Javascript Numeric Formatting
View the source...
This script formats field entry if it is numeric.