Warning: file_exists(): File name is longer than the maximum allowed path length on this platform (260): C:\wwwroot\www.ynlykl.com/wp-content/themes/mkBlog/single-post-%e3%80%90js%e3%80%91tofixed%e6%96%b9%e6%b3%95%e8%ae%be%e7%bd%ae%e5%b0%8f%e6%95%b0%e7%82%b9%e4%bd%8d%e6%95%b0%e5%90%8e%e5%86%8d%e8%bf%9b%e8%a1%8c%e8%ae%a1%e7%ae%97%ef%bc%8c%e6%95%b0%e6%8d%ae%e5%87%ba.php in C:\wwwroot\www.ynlykl.com\wp-includes\template.php on line 703

Warning: file_exists(): File name is longer than the maximum allowed path length on this platform (260): C:\wwwroot\www.ynlykl.com/wp-content/themes/mkBlog/single-post-%e3%80%90js%e3%80%91tofixed%e6%96%b9%e6%b3%95%e8%ae%be%e7%bd%ae%e5%b0%8f%e6%95%b0%e7%82%b9%e4%bd%8d%e6%95%b0%e5%90%8e%e5%86%8d%e8%bf%9b%e8%a1%8c%e8%ae%a1%e7%ae%97%ef%bc%8c%e6%95%b0%e6%8d%ae%e5%87%ba.php in C:\wwwroot\www.ynlykl.com\wp-includes\template.php on line 706

Warning: file_exists(): File name is longer than the maximum allowed path length on this platform (260): C:\wwwroot\www.ynlykl.com/wp-includes/theme-compat/single-post-%e3%80%90js%e3%80%91tofixed%e6%96%b9%e6%b3%95%e8%ae%be%e7%bd%ae%e5%b0%8f%e6%95%b0%e7%82%b9%e4%bd%8d%e6%95%b0%e5%90%8e%e5%86%8d%e8%bf%9b%e8%a1%8c%e8%ae%a1%e7%ae%97%ef%bc%8c%e6%95%b0%e6%8d%ae%e5%87%ba.php in C:\wwwroot\www.ynlykl.com\wp-includes\template.php on line 709
【JS】toFixed方法设置小数点位数后再进行计算,数据出错问题 | 越努力越快乐

【JS】toFixed方法设置小数点位数后再进行计算,数据出错问题

gengboxb 974 0

情况:

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

发表评论 取消回复
表情 图片 链接 代码

分享