繁体   English   中英

在Javascript中添加百分号

[英]Adding a percentage sign in Javascript

在Javascript中我试图在我的函数结束时添加%符号,但是当我测试它时我得到NaN。

function percentReadyForDegree(creditsEarned) { 
    return Math.round((creditsEarned / 71) * 100 + "%");
}  

percentReadyForDegree(30);

您需要将一个数字传递给Math.round 在你的代码中,你传递一个字符串。 操作添加标志:

return Math.round(creditsEarned / 71 * 100) +'%';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM