jQuery Number Format

The update gives you more options for returning, or replacing numbers, along with as-you-type formatting for input fields!

Original Article:

Don't you wish there was a way to format numbers using JavaScript, that is as easy, or even easier than PHP's number formatting functions? I do.

In fact, many of my clients want consistently formatted numbers to be displayed on screen. Usually, I'm already calculating various numbers in JavaScript based on user input, and inserting the raw number into the document using the jQuery .text() function. But that doesn't give you consistent formatting.

There are loads of great methods around for formatting numbers. My favourite is the excellent phpjs.org library.

To make this even more convenient though, I wrapped it in a jQuery plugin which does the same thing as the .text() method — with the added ability to format the value with any number of decimal places, specifying the decimal point symbol, and thousands separator symbol.