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 badges
Add a comment  | 

4 Answers 4

Reset to default 7

According 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