[英]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.