Значения SUM с использованием Numbers.js - PullRequest
0 голосов
/ 28 февраля 2019

Я пытаюсь суммировать значения из значений, разделенных точкой, например:

enter image description here

Вот как я это делаю:

 computed: {
            total: function(){
                return Number(this.ValorImovelPatrimonio.replace('.','')) + Number(this.ValorAutosPatrimonio.replace('.','')) + Number(this.ValorOutrosPatrimonio.replace('.','')) + Number(this.ValorAcoesPatrimonio.replace('.','')) + Number(this.ValorInvestimentosPatrimonio.replace('.',''));
            },

Любые советы о том, как использовать его с (или нет) Numbers.js?

1 Ответ

0 голосов
/ 28 февраля 2019

Вместо Number вы можете использовать parseInt, а также использовать replace с модификатором g для замены всех вхождений:

 computed: {
        total: function(){
            return parseInt(this.ValorImovelPatrimonio.replace(/\./g,'')) + parseInt(this.ValorAutosPatrimonio.replace(/\./g,'')) + parseInt(this.ValorOutrosPatrimonio.replace(/\./g,'')) + parseInt(this.ValorAcoesPatrimonio.replace(/\./g,'')) + parseInt(this.ValorInvestimentosPatrimonio.replace(/\./g,''));
        },
...