Easy Number and Currency Formatting Library - autoNumeric

Easy Number and Currency Formatting Library - autoNumeric
File Size: 344 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT

autoNumeric is an useful JavaScript 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 it:

1. Include the latest autoNumeric.js on the webpage

<script src="/path/to/autoNumeric.js" type=text/javascript> </script>

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

  <input type="text" class="demo">

3. Initialize the autoNumeric library and done.

new AutoNumeric('.demo', { currencySymbol : '$' });

4. Options and defaults. You can also pass the following options via HTML5 data attributes.

// if the decimal places should be padded with zeroes
allowDecimalPadding: true,

// where should be positioned the caret on focus
caretPositionOnFocus              : true,

// Defines if a local list of AutoNumeric objects should be kept when initializing this object.
createLocalList                   : true,

// The currency symbol string
currencySymbol                    : true,

// Defines where the currency symbol should be placed (before of after the numbers)
currencySymbolPlacement           : true,

// what decimal separator character is used
decimalCharacter                  : true,

// Allow to declare an alternative decimal separator which is automatically replaced by `decimalCharacter` when typed
decimalCharacterAlternative       : true,

// the default number of decimal places to show on the formatted value, and keep for the precision
decimalPlaces                     : true,

// how many decimal places should be kept for the raw value rawValue
decimalPlacesRawValue             : true,

// how many decimal places should be visible when the element is unfocused
decimalPlacesShownOnBlur          : true,

// how many decimal places should be visible when the element has the focus
decimalPlacesShownOnFocus         : true,

// Helper option for Asp.net postback
defaultValueOverride              : true,

// how many numbers should be grouped together
digitalGroupSpacing               : true,

// the thousand grouping separator character
digitGroupSeparator               : true,

// the number that divides the element value on focus
divisorWhenUnfocused              : true,

// what should be displayed in the element if the raw value is an empty string ''
emptyInputBehavior                : true,

// if the custom and native events triggered by AutoNumeric should bubble up or not
eventBubbles                      : true,

// if the custom and native events triggered by AutoNumeric should be cancelable
eventIsCancelable                 : true,

// This option is AutoNumeric's "strict mode" (aka 'debug' mode), which allows autoNumeric to strictly analyse the options given by the user, and fails if an unknown options is used in the settings object
failOnUnknownOption               : true,

// if the default value will be formatted on initialization
formatOnPageLoad                  : true,

// Set the undo/redo history table size
historySize                       : true,

// Allow the user to cancel and undo the changes he made to the given autonumeric-managed element, by pressing the Escape key
isCancellable                     : true,

// Controls the leading zero behavior
leadingZero                       : true,

// the maximum/minimum possible value a user can enter
maximumValue                      : true,
minimumValue                      : true,

// allows the user to increment or decrement the element value with the mouse wheel
modifyValueOnWheel                : true,

// adds brackets-like characters on negative values when unfocused
negativeBracketsTypeOnBlur        : true,

// Placement of the negative/positive sign relative to the currencySymbol option
negativePositiveSignPlacement     : true,

// the negative sign symbol to use
negativeSignCharacter             : true,

// if the element should have event listeners activated on it
noEventListeners                  : true,

// Manage how autoNumeric react when the user tries to paste an invalid number
onInvalidPaste                    : true,

// Defines how the value should be formatted when wanting a localized version of it
outputFormat                      : true,

// Override the minimum and maximum limits
overrideMinMaxLimits              : true,

// the positive sign symbol to use
positiveSignCharacter             : true,

// Divides the formatted value shown in the AutoNumeric element and store the divided result in rawValue
rawValueDivisor                   : true,

// if the element (<input> or another allowed html tag) should be set as read only on initialization
readOnly                          : true,

// the rounding method to use
roundingMethod                    : true,

// Set to true to allow the decimalPlacesShownOnFocus value to be saved with sessionStorage
saveValueToSessionStorage         : true,

// Determine if the select all keyboard command will select the complete input text, or only the input numeric value
selectNumberOnly                  : true,

// if the element value should be selected on focus
selectOnFocus                     : true,

// how the serialize functions should treat the spaces
serializeSpaces                   : true,

// if the element value should be converted to the raw value on focus or mouseenter, (and back to the formatted on blur or mouseleave)
showOnlyNumbersOnFocus            : true,

// Allow the positive sign symbol positiveSignCharacter to be displayed for positive numbers
showPositiveSign                  : true,

// if warnings should be shown in the console
showWarnings                      : true,

// the rules that calculate the CSS class(es) to apply on the element, based on the raw unformatted value
styleRules                        : true,

// Add a text on the right hand side of the element value
suffixText                        : true,

// the symbol placed as a suffix when not in focus or hovered
symbolWhenUnfocused               : true,

// if the element value should be unformatted when the user hover his mouse over it while holding the Alt key
unformatOnHover                   : true,

// When a submit event is detected in the parent form element, temporarily removes the formatting and set the rawValue in each AutoNumeric child elements
unformatOnSubmit                  : true,

// Provides a way for automatically replacing the formatted value with a pre-defined string, when the raw value is equal to a specific value
valuesToStrings                   : true,

// if the AutoNumeric element should watch external changes made without using .set()
watchExternalChanges              : true,

// when the wheel event will increment or decrement the element value
wheelOn                           : true,

// Defines by how much the element value should be incremented/decremented on the wheel event
wheelStep                         : true,

// Additional information that are added to the `settings` object :
allowedAutoStrip                  : true,
isNegativeSignAllowed             : true,
isPositiveSignAllowed             : true,
mIntNeg                           : true,
mIntPos                           : true,
numRegAutoStrip                   : true,
originalDecimalPlaces             : true,
originalDecimalPlacesRawValue     : true,
stripReg                          : true,


v4.4.0 (2018-08-04)

  • Add a feature where emptyInputBehavior could be set to the minimum or maximum value, emptyInputBehavior now accepts either a number (or a string representing a number), or the 'min' or 'max' option
  • Fix the emptyInputBehavior validation test when checking the value limits
  • Allow emptyInputBehavior to be set to min, max, or a number

v4.3.7 (2018-07-28)

  • Fixed: Currency at wrong position for empty fields with euro/french preset after typing minus sign
  • Fixed: Entering a single minus character in a negativeBracketsTypeOnBlur input invert the currency sign and that minus sign

v4.3.6 (2018-07-27)

  • Fixed: 'Bug on form reset' that was re-opened
  • AutoNumeric now listens to the reset event on the parent form, and react accordingly if detected

v4.3.4 (2018-07-26)

  • Fixed: Change event not firing depending on cursor movement

v4.3.3 (2018-07-24)

  • Fixes Pasting a negative value over a negative value that as a currency symbol and its numbers selected throws an error
  • Refactor the _onPaste() handler by removing duplicated parts
  • Fix the initialization call new AutoNumeric() where using as arguments a string (element selector), a number (initial value) and an array (array of options), in that particular order, would not be recognized

v4.3.1 (2018-07-24)

  • Modify the tenTrillions and oneBillion limits to be exact
  • Remove the maximumValue and minimumValue tenTrillionsNoDecimals option, and update tenTrillions so that it equals ten trillions
  • The tenTrillions sub-option is now equal to '10000000000000', and the oneBillion sub-option is now equal to '1000000000'
  • This change was long overdue since we modified in v4.0.0-beta.22 how the number of decimal places was defined by the user using the decimalPlaces options instead of adding a specific number of decimal to the min/max values.

v4.3.0 (2018-06-02)

  • Allow non-input tags with the readOnly option to set the contenteditable attribute to false
  • Fix the readonly and contenteditable attributes so that they can be updated to read/write mode
  • Modify _setReadOnly() so that it always sets the element to read-only mode
  • Create a new _setReadWrite() function that sets the element to read-write mode
  • Create a new _setWritePermissions() function that sets the element read only/write mode according to the readOnly setting
  • Fixed Event listeners are not set/reset on option updates.
  • Fixed Internet Explorer 11 throws when freezing the options


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