JavaScript: Rounding Numbers to One Decimal Place in Reduce Method
"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.

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