Easy Numbers and Currency Formatting Plugin - autoNumeric

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

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

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

3. Call the plugin

 jQuery(function($) {

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 Logs:

v1.9.46 (2016-09-12)

  • multiple fixes

v1.9.45 (2016-06-14)

  • Modified the "set" method to handle NaN

v1.9.44 (2016-06-07)

  • Fixed destroy method
  • Added Typings support

v1.9.43 (2015-12-20)

  • UMD support

v1.9.42 (2015-11-21)

  • Fixed bug when pasting using ctrl & v keys

v1.9.41 (2015-11-04)

  • Fixed bug that allowed two currency symbols

v1.9.40 (2015-10-26)

  • Fixed bug when pasting value and the decimal seperator is a comma ","

v1.9.39 (2015-07-18)

  • Fixed 'aForm'option.

v1.9.38 (2015-07-13)

  • Added / fixed option to address asp.Net WebForm postback.
  • please see the readme section on default settings & options

v1.9.37 (2015-05-25)

  • Added / fixed support for asp.Net WebForm postback.
  • During postback the default value is re-rendered showing the updated value
  • Because autoNumeric cannot distinguish between a page re-load and asp.net form postback, the following HTML data attribute is REQUIRED (data-an-default="same value as the value attribute") to prevent errors on postback

v1.9.36 (2015-05-11)

  • Rewrote the "getString" & "getArray" methods to index successful elements and inputs that are controlled by autoNumeric. This ensures the proper input index is used when replacing the formatted value.
  • Added support for FireFox for Mac meta key "keycode 224"

v1.9.35 (2015-04-20)

  • Revert 'set' back to version 1.9.34

v1.9.34 (2015-03-09)

  • Modified the 'set', 'getString' & 'getArray' methods
  • Modified the 'nBracket' function
  • General code clean up   

v1.9.33 (2015-02-16)

  • Fixed bug in "ctrl + v" paste event
  • Fixed bug when the "update" method is called in the "onfocus" event
  • Fixed the "getString" & "getArray" methods when multiple inputs share the same name

v1.9.30 (2015-01-13)

  • Fixed in 1.9.29 too interest in Ohio State vs. Oregon

v1.9.29 (2014-12-08)

  • Fixed focusout event when the thousand separator is a period "." and only one is present "x.xxx" with not other alpha characters.
  • Fixed bug introduced in 1.9.27.

v1.9.27 (2014-12-08)

  • Merged a mod that makes the defaults public and over ridable.
  • Fixed page reload when the thousand separator is a period "."

v1.9.26 (2014-10-08)

  • Fixed "getString" & "getArray" methods when multiple forms having some shared named inputs

v1.9.25 (2014-08-02)

  • Fixed mRound option "round-half-even"
  • Modified the "set" method to not throw an error when trying to "set" a null value

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.