使用 ES6 的数组方法 map() 来遍历数组中的每个对象,并将 customerAnnualReductionRate 和 supplierAnnualReductionRate 转换为百分数的小数形式。

const data = [
    {
        'del': 0,
        'createBy': 'GW00281461',
        'createTime': '2023-09-20 10:37:14',
        'updateBy': 'GW00281461',
        'updateTime': '2023-09-20 10:37:14',
        'id': 361,
        'quotationConfirmId': 141,
        'predictionYear': '2022',
        'output': 20000,
        'supplierAnnualReductionRate': '77',
        'customerAnnualReductionRate': '55',
        'netProfit': '983221278430.00',
        'unitPrice': 90000000,
        'netProfitMargin': -0.010115445251337448,
        'sort': 1,
        'jgPlaceName': '徐水工厂',
        'directMaterial': 339.55,
        'directMaterialAll': -516116000,
        'productionCost': 5163454.209999999,
        'otherCost': null,
        'profitCoefficient': null,
        'salesVolume': -97200000000000,
        'otherCosts': 103785200199.99998,
        'operatingProfit': -97303269084200
    },
    // ... other objects
];

const convertedData = data.map(obj => ({
    ...obj,
    customerAnnualReductionRate: parseFloat(obj.customerAnnualReductionRate) / 100,
    supplierAnnualReductionRate: parseFloat(obj.supplierAnnualReductionRate) / 100
}));

console.log(convertedData);

这样,数组中的每个对象的 customerAnnualReductionRate 和 supplierAnnualReductionRate 属性都会被转换为百分数的小数形式。

ES6 将数组中的 customerAnnualReductionRate 和 supplierAnnualReductionRate 转换为百分数的小数

原文地址: https://www.cveoy.top/t/topic/flaU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录