Number Formatting
General
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():
stripNonNumeric() then numberFormat():
Notes
- Created by: Justin Barlow
- Web Site: http://www.netlobo.com/
- Posted: May 12, 2008
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: numbFormat.js
Head
Paste this code into the HEAD section of your HTML document.
Body
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