情况:
let num = 409600; let total = 433927; let percentData = (num / total).toFixed(3) * 100; console.log(percentData) // 94.39999999999999
解决:
在括号里面先乘上100
let num = 409600; let total = 433927; let percentData = (num * 100 / total).toFixed(1); console.log(percentData) // 94.4
本文作者为gengboxb,转载请注明。