Sha256: a9885554ac512abef5586eb4ef3cda7d476f530f5d7faf13fc025ff68dd31a1f
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
/* @Author: Pasquale Cappa Spina; @Website: http://pasqualecappaspina.com; @Description: Plugin jQuery for format number insert in input; */ (function ( $ ) { $.fn.pcsFormatNumber = function( options ) { // Default options. var settings = $.extend({ // These are the defaults. decimal_separator: ".", number_separator: ",", currency: "€", to_fixed: 2 }, options ); // Format var el = $(this); var val = el.val(); el.val(formatNumber(val.replace(settings.decimal_separator, settings.number_separator), settings.currency)); el.change(function(event) { var val = $(this).val(); $(this).val(formatNumber(val, settings.currency)); }); // Functions function formatNumber(number, currency) { number = number.replace(currency, ''); number = number.replace(settings.decimal_separator, ""); number = number.replace(settings.number_separator, settings.decimal_separator); number = Number(number.trim()); return currency + ' ' + number.toFixed(settings.to_fixed).replace(/(\d)(?=(\d{3})+\.)/g, '$1'+settings.number_separator).replace(settings.decimal_separator, settings.number_separator).replace(settings.number_separator, settings.decimal_separator); } }; }( jQuery ));
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ready_boot_dash-1.1.1 | vendor/assets/javascripts/vendor/pcsFormatNumber.jquery.js |
ready_boot_dash-1.0.0 | vendor/assets/javascripts/vendor/pcsFormatNumber.jquery.js |