2013-09-27 237 views
1

在Javascript中,我試圖在函數的末尾添加%符號,但是當我測試它時,我得到了NaN。在Javascript中添加百分比

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

percentReadyForDegree(30); 

回答

4

您需要將一個數字傳遞給Math.round。在你的代碼中,你傳遞一個字符串。在之後添加標誌操作:

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

我知道這很簡單。謝謝!!! – GMan