Download
User Rating: 0/5 ( 0 votes)
jQuery price format is a plugin used to format input fields into fields capable to contain price. It limits the input field to able to receive only numbers, and automatically inserts the decimal point as you type. Such functionality is needed when developing accounting applications or online shops.
Source: github.com
1. INCLUDE JS FILES
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.priceformat.js"></script>
2. HTML
<label for="price">Price: </label>
<input id="price" type="text"/>
3. JAVASCRIPT
$(document).ready(function () {
$('#price').priceformat({
defaultValue: 10050,
decimalSeparator: '.',
thousandsSeparator: ','
});
});
The default value is 100.50, with . as a decimal separator and , as thousands separator (for example 1,300.50)
4. OPTIONS
The plugin can accept few options either via the constructor or html data-* attributes.
Default value integer, default = 0
Specified either via defaultValue in plugin constructor or value attribute on the input field.
Sets the initial value of the input. For example to set the initial value to 100.50, specify the default value as 10050
Decimals Separator char, default = .
Specified either via decimalSeparator in plugin constructor or data-decimal-separator attribute on the input field.
Sets the decimals separator character.
Thousands Separator char, default = null
Specified either via thousandsSeparator in the plugin constructor or data-thousands-separatorattribute on the input field.
Sets the thousands separator character, default to null means no character will be used.