Number Formatting | JavaScriptSource

Number Formatting

Justin Barlow May 12, 2008


These two functions clean up and format numbers quite nicely. One function takes any decimal number, negative or positive, and formats it by adding commas every three digits. The other function strips any non-numeric characters from a string leaving you with a valid decimal number. It considers the minus sign and the period to be numeric and will not strip them unless the minus sign is not at the beginning of the number or there is more than one period. These functions make use of regular expressions to do the heavy lifting.



stripNonNumeric() then numberFormat():


Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: numbFormat.js


Paste this code into the HEAD section of your HTML document.


Paste this code into the BODY section of your HTML document

Leave a Response

(1 comment)

Hi,[br /][br /]this is nice one...[br /][br /]good

Navin May 16, 2008