简体   繁体   English

在Javascript中添加百分号

[英]Adding a percentage sign in Javascript

In Javascript I'm trying to add a % sign at the end of my function but I get NaN when I test it. 在Javascript中我试图在我的函数结束时添加%符号,但是当我测试它时我得到NaN。

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

percentReadyForDegree(30);

You need to pass a number to Math.round . 您需要将一个数字传递给Math.round In your code you're passing a string. 在你的代码中,你传递一个字符串。 Add the sign after the operation: 操作添加标志:

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

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

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