Plugins

User login
Can't find a Plugin?

Can't find a Plugin you are looking for? Check out the jQuery Wiki page.

Are you a plugin developer? Please move your plugin over to this site.

Website Bug or Feature Request?

Found a bug on the new jQuery Plugin website? Have a feature request?

Submit it to the jQuery Plugin website issue queue to ensure it is noticed!

NumberFormatter - International Support for Number Formatting


Average rating
(2 votes)

This plugin is a NumberFormatter plugin. Number formatting is likely familiar to anyone who's worked with server-side code like Java or PHP and who has worked with internationalization. For example, a number that we would write in the US as "1,250,500.75" would be written differently in different countries: "1.250.500,75" in Germany, "1 250 500,75" in France, and "1'250'500.75" in Switzerland, and "125,0500.75" in Japan. The number is exactly the same, but it's just written using a different format when presented to users of the web application.

Here's a typical use case for what I'm describing. You have an input field in your web application that asks a person for their salary. In the US, the user can type in a varied forms of input - "$65000", "65,000", "65000", "65,000.00". All these numbers are exactly the same, but we want to control how these numbers look on the screen.

Here's an example of how you'd use this plugin.

$("#salary").blur(function(){
    $(this).format({format:"#,###.00", locale:"de"});
});

Syntax

The syntax for the formatting is:

  • 0 = Digit
  • # = Digit, zero shows as absent
  • . = Decimal separator
  • - = Negative sign
  • , = Grouping Separator
  • % = Percent (multiplies number by 100)

New in Version 1.1

I recommend everyone to move to the 1.1 version of the plugin, as it is more stable and contains more features.

  • Added support for using the "%" character in formats. This will convert all numbers into their percent equivalent by multiplying them by 100. For example, if a user enters "0.125" and you specify a format of "#.0%", the text will be formatted to "12.5%"
  • Added support for prefixes and suffixes that aren't part of the syntax. This is especially beneficial for currencies. For example, if a user enters "12.34" and you specify a format of "$#.##", the text will be formatted to "$12.34". Also, if you specify something like "#.## JPY", the same text will be formatted to "12.34 JPY".
  • Added special exceptions for negative numbers to appear before any prefixes. So, for example, you can specify a format of "-$#.##" to display a formatted text of "-$12.34", or "$-#.##" to display a formatted text of "$-12.34", depending on your needs.
  • The parse() function has been updated with all the above fixes as well.

Releases

Official releasesDateSizeLinksStatus
1.1.02009-Jan-269.95 KBRecommended for 1.2.xThis is currently the recommended release for 1.2.x.