"this.floorElvTotalNum = this.patrolStatisticsList.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0).toFixed(1);"\nTo keep the decimal places to one, you can use the toFixed() method after calculating the total. Here's an example:\n\njavascript\nthis.floorElvTotalNum = this.patrolStatisticsList.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0).toFixed(1);\n\n\nThis will convert the result to a string with one decimal place.

JavaScript: Rounding Numbers to One Decimal Place in Reduce Method

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

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