【问题标题】:Performing arithmetic operations in Postman?在 Postman 中执行算术运算?
【发布时间】:2019-04-11 17:02:20
【问题描述】:

我正在尝试获取包含我使用 Postman 发送的数值总和的响应。但相反,我得到了连接值。请帮帮我。

这是我的代码 sn-p:

 const {
            amount,
            old_balance,
            account_number,
            transaction_type,
            cashier
        } = req.body;

        let x, y, sum; 

        x = amount
        y = old_balance; 
        sum = x + y; 

        const newDebit = {

            created_on: create_on,
            transaction_id: transactions.length + 1,
            account_number: parseInt(account_number),
            amount: parseFloat(amount),
            cashier: parseInt(cashier),
            transaction_type: transaction_type,
            old_balance: parseFloat(old_balance),
            new_balance: parseInt(sum)
        }

【问题讨论】:

    标签: node.js express postman


    【解决方案1】:

    您应该首先将字符串转换为 int,然后添加 x 和 y。把代码改成

    const {
        amount,
        old_balance,
        account_number,
        transaction_type,
        cashier
    } = req.body;
    
    let x, y, sum; 
    
    x = amount
    y = old_balance; 
    sum = parseInt(x) + parseInt(y); 
    
    const newDebit = {
        created_on: create_on,
        transaction_id: transactions.length + 1,
        account_number: parseInt(account_number),
        amount: parseFloat(amount),
        cashier: parseInt(cashier),
        transaction_type: transaction_type,
        old_balance: parseFloat(old_balance),
        new_balance: sum
    }
    

    【讨论】:

    • 非常感谢巴拉特!我不敢相信我错过了那个小东西。问题解决了。
    猜你喜欢
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 2022-06-14
    • 2017-04-15
    • 2012-09-12
    相关资源
    最近更新 更多