JavaScript : 6 Basic and Useful Number Format Functions

1. by Matt:

Basically, you can pass in a String as the format that contain any one number,and the result will replace the number in the format String with the properly formatted Number object. See the comment block for details. format _number_01.js:

I noticed that some countries (e.g. Netherlands) use the comma and period exactly opposite (e.g. 1.234,56 instead of 1,234.45) ,but it can be easily modified.

2. by Mredkj (Add commas)

addCommas.js: netlobo(Strip Non-Numeric Characters From a String)

This function strips any non-numeric characters from a string leaving you with a valid decimal number. This function considers the minus sign (hyphen) 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, stripNonNumeric.js:

4. by Stephen Chapman

With this function,we can easily select different formatting by changing the values in the second through eighth parameters. The second parameter is the number of decimal places that the number should have. formatNumber.js: java-scripts

This function formats a numeric value passed in to it with specified number of decimal values. Numeric value will not be rounded. format_number.js:

6. by geocities

This function formats a number with a number of decimal places from 0 to 3. formatNumber .js:

One thought on “JavaScript : 6 Basic and Useful Number Format Functions

Leave a Reply

Your email address will not be published. Required fields are marked *