Plugins

The plugins site is currently in development.

We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.

NumberFormatter - International Support for Number Formatting


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.

Downloads



5
Your rating: None Average: 5 (2 votes)