admin管理员组文章数量:1333210
I'm using autonumeric.js
to generate currency number format, the problem is autonumeric's generating 2 more zeros after comma. e.g 40560000 became 40.560.000,00
I want to remove the last 2 zeros, so instead of 40.560.000,00 the result of autonumeric will be 40.560.000
This is my script :
$('td.sub_total').autoNumeric('init', {aSep: '.', aDec: ','});
$('td.vat').autoNumeric('init', {aSep: '.', aDec: ','});
$('td.total').autoNumeric('init', {aSep: '.', aDec: ','});
Any help will be much appreciated, thank you.
I'm using autonumeric.js
to generate currency number format, the problem is autonumeric's generating 2 more zeros after comma. e.g 40560000 became 40.560.000,00
I want to remove the last 2 zeros, so instead of 40.560.000,00 the result of autonumeric will be 40.560.000
This is my script :
$('td.sub_total').autoNumeric('init', {aSep: '.', aDec: ','});
$('td.vat').autoNumeric('init', {aSep: '.', aDec: ','});
$('td.total').autoNumeric('init', {aSep: '.', aDec: ','});
Any help will be much appreciated, thank you.
Share Improve this question edited Jul 28, 2016 at 13:13 Rajesh 24.9k5 gold badges50 silver badges83 bronze badges asked Jul 28, 2016 at 13:09 M AnsyoriM Ansyori 4888 silver badges22 bronze badges4 Answers
Reset to default 7According to the documentation, you can simply use the mDec
key in the object.
Example:
$('td.sub_total').autoNumeric('init', {aSep: '.', aDec: ',', mDec: '0'});
$('td.vat').autoNumeric('init', {aSep: '.', aDec: ',', mDec: '0'});
$('td.total').autoNumeric('init', {aSep: '.', aDec: ',', mDec: '0'});
As mentioned in a comment by Alex:
for autoNumeric v4+ the proper way to do this is to use:
{decimalPlaces:'0'}
autonumeric.js provide option (aPad) to remove unneccessary zero numbers. You can try this flow the source code above. You can try:
// wacth change opts and re-instance autoNumeric
scope.$watch(() => {
return $(element).attr('kv-auto-numeric'); // set a watch on the actual DOM value
},
(val: string) => {
opts = angular.extend({}, this.options, scope.$eval(val)) as AutoNumericOptions;
// remove unneccessary zero numbers
opts.aPad = false;
element.autoNumeric('update', opts);
});
Autonumeric contains an option called "allowDecimalPadding". If this option is set as true, padding is only done when there are some decimals.
Autonumeric npm.js
本文标签: javascriptRemoving last two Zeros AutoNumericjsJQueryStack Overflow
版权声明:本文标题:javascript - Removing last two Zeros [AutoNumeric.js, JQuery] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739414722a2162234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论