Javascript 使用Numbers.js求和值
我试着将由点分隔的值求和,如: 我是这样做的:Javascript 使用Numbers.js求和值,javascript,vuejs2,sum,numbers,Javascript,Vuejs2,Sum,Numbers,我试着将由点分隔的值求和,如: 我是这样做的: computed: { total: function(){ return Number(this.ValorImovelPatrimonio.replace('.','')) + Number(this.ValorAutosPatrimonio.replace('.','')) + Number(this.ValorOutrosPatrimonio.replace('.','')) +
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一起使用的任何提示?而不是
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,''));
},