vuejs2中的和值

问题描述 投票:0回答:1

嗨我有这个vuejs2代码

totals() {
    this.total = 0;
    console.log(this.total_without_discount);
    console.log(this.total_taxs);
    console.log(this.total_discount);
    this.total += this.total_without_discount;
    this.total += this.total_taxs;
    this.total += this.total_discount;
    return Number(this.total).toFixed(this.comma);
},

现在,当我得到结果回到我gat南所有这些功能都在computed我怎么能总结整数函数内的值并返回它谢谢

vue.js vuejs2
1个回答
2
投票

使用parseIntparseFloat,具体取决于所需的数据类型和精度:

totals() {
    this.total = 0;

    this.total += parseFloat(this.total_without_discount);
    this.total += parseFloat(this.total_taxs);
    this.total += parseFloat(this.total_discount);

    return parseFloat(this.total).toFixed(this.comma);
},
© www.soinside.com 2019 - 2024. All rights reserved.