Easy Numbers and Currency Formatting Plugin - autoNumeric

Easy Numbers and Currency Formatting Plugin - autoNumeric
File Size: 48.3 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

How to start using jQuery?

More in this category...

View our Recommended Plugins

TOP 100 jQuery Plugins 2013

autoNumeric is an useful jQuery plugin for international currency formatting as well as numbers formatting. It supports almost all the major international numeric formats and currency signs used in Europe, North and South America, Asia and India.

You might also like:

How to use (Use both HTML5 data and options.):

1. Include the latest jQuery library and autoNumeric.js

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"> </script>
<script src="autoNumeric-1.8.8.js" type=text/javascript> </script>

2. Create a input field with HTML5 data for the German Euro

<form>
  <input type="text" id="DEMO" data-a-sign="€ " data-a-dec="," data-a-sep=".">
</form>

3. Call the plugin

<script>
 jQuery(function($) {
      $('#DEMO').autoNumeric('init');    
  });
</script>

4. Options and defaults.

 /** allowed numeric values
 * please do not modify
 */
aNum: '0123456789',
/** allowed thousand separator characters
 * comma = ','
 * period "full stop" = '.'
 * apostrophe is escaped = '\''
 * space = ' '
 * none = ''
 * NOTE: do not use numeric characters
 */
aSep: ',',
/** digital grouping for the thousand separator used in Format
 * dGroup: '2', results in 99,99,99,999 common in India for values less than 1 billion and greater than -1 billion
 * dGroup: '3', results in 999,999,999 default
 * dGroup: '4', results in 9999,9999,9999 used in some Asian countries
 */
dGroup: '3',
/** allowed decimal separator characters
 * period "full stop" = '.'
 * comma = ','
 */
aDec: '.',
/** allow to declare alternative decimal separator which is automatically replaced by aDec
 * developed for countries the use a comma ',' as the decimal character
 * and have keyboards\numeric pads that have a period 'full stop' as the decimal characters (Spain is an example)
 */
altDec: null,
/** allowed currency symbol
 * Must be in quotes aSign: '$', a space is allowed aSign: '$ '
 */
aSign: '',
/** placement of currency sign
 * for prefix pSign: 'p',
 * for suffix pSign: 's',
 */
pSign: 'p',
/** maximum possible value
 * value must be enclosed in quotes and use the period for the decimal point
 * value must be larger than vMin
 */
vMax: '9999999999999.99',
/** minimum possible value
 * value must be enclosed in quotes and use the period for the decimal point
 * value must be smaller than vMax
 */
vMin: '0.00',
/** max number of decimal places = used to override decimal places set by the vMin & vMax values
 * value must be enclosed in quotes example mDec: '3',
 * This can also set the value via a call back function mDec: 'css:#
 */
mDec: null,
/** method used for rounding
 * mRound: 'S', Round-Half-Up Symmetric (default)
 * mRound: 'A', Round-Half-Up Asymmetric
 * mRound: 's', Round-Half-Down Symmetric (lower case s)
 * mRound: 'a', Round-Half-Down Asymmetric (lower case a)
 * mRound: 'B', Round-Half-Even "Bankers Rounding"
 * mRound: 'U', Round Up "Round-Away-From-Zero"
 * mRound: 'D', Round Down "Round-Toward-Zero" - same as truncate
 * mRound: 'C', Round to Ceiling "Toward Positive Infinity"
 * mRound: 'F', Round to Floor "Toward Negative Infinity"
 */
mRound: 'S',
/** controls decimal padding
 * aPad: true - always Pad decimals with zeros
 * aPad: false - does not pad with zeros.
 * aPad: `some number` - pad decimals with zero to number different from mDec
 * thanks to Jonas Johansson for the suggestion
 */
aPad: true,
/** places brackets on negative value -$ 999.99 to (999.99)
 * visible only when the field does NOT have focus the left and right symbols should be enclosed in quotes and seperated by a comma
 * nBracket: null, nBracket: '(,)', nBracket: '[,]', nBracket: '<,>' or nBracket: '{,}'
 */
nBracket: null,
/** Displayed on empty string
 * wEmpty: 'empty', - input can be blank
 * wEmpty: 'zero', - displays zero
 * wEmpty: 'sign', - displays the currency sign
 */
wEmpty: 'empty',
/** controls leading zero behavior
 * lZero: 'allow', - allows leading zeros to be entered. Zeros will be truncated when entering additional digits. On focusout zeros will be deleted.
 * lZero: 'deny', - allows only one leading zero on values less than one
 * lZero: 'keep', - allows leading zeros to be entered. on fousout zeros will be retained.
 */
lZero: 'allow',
/** determine if the default value will be formatted on page ready.
 * true = automatically formats the default value on page ready
 * false = will not format the default value
 */
aForm: true,
/** future use */
onSomeEvent: function () {}

Change Log:

v1.9.24 (2014-06-30)

  • Changed the case on the supported elements
  • This was required because jQuery.prop('tagName') returns upper-case on html5 pages and returns lower-case on xmhtl pages

v1.9.22 (2014-04-21)

  • fix bug and code cleanup

v1.9.21 (2014-04-01)

  • Mod to checkValue function to handle empty string - thanks to jedichenbin.
  • If CHF rounding is used decimal is automatically set to 2 places

v1.9.20 (2014-03-31)

  • increase vMax default value

v1.9.19 (2014-03-24)

  • fix format of text elements on pageload

v1.9.18 (2013-12-04)

  • fix format of text elements on pageload

v1.9.17 (2013-09-28)

  • Fixed leading zero on page load

v1.9.14 (2013-09-12)

  • Bug fix on checkValue function

v1.9.14 (2013-8-6)

  • fixed bugs

v1.9.11 (2013-6-23)

  • fixed "get" method

v1.9.11 (2013-6-23)

  • Another mod to the 'set' method.
  • Fixed the 'set' method to handle page reload using the back button.

v1.9.9 (2013-6-23)

  • Fixed how non-input tags default value is handled. When the default is an empty string and aSign is not empty the return value is now and empty string.
  • Modified how default values are handled when the decimal character equals ',' comma. Your default value can now use either a a period '.' or comma ',' as the decimal separator
  • Modified the caret placement on focusin (tab in). If only the currency sign is visible the caret is placed in the proper location depending on the sign placement (prefix or suffix).

v1.9.8 (2013-5-20)

  • Changed bind / unbind to on / off.
  • added lastSetValue to settings - this saves the unrounded value from the set method - $('selector').data('autoNumeric').lastSetValue; - helpful when you need to change the rounding accuracy

This awesome jQuery plugin is developed by BobKnothe. For more Advanced Usages, please check the demo page or visit the official website.