2016-12-14 9 views
-1

私は最大2小数点以下のパーセントを取得したいと思います。この合計スコアのようなIM得る出力26.666666666666668%JavaScriptで2小数点以下の割合を取得するには

所望の出力26.66パーセントである

if(pos >= questions.length){ 
     test.innerHTML = "<h2>You gave "+correct+" CORRECT answers out of "+questions.length+" questions </h2><br/><h3>Total Score is "+correct/questions.length * 100 +" %</h3>"; 
     _("test_status").innerHTML = "Quiz 1 Completed"; 
     pos = 0; 
     correct = 0; 
     return false; 
    } 
+3

'(正しい/ questions.length * 100).toFixed(2)' – Satpal

答えて

0
<button onclick="myFunction()">Try it</button> 

<p id="demo"></p> 

<script> 
function myFunction() { 
    var num = 26.666666666666668; 
    var n = num.toFixed(2) 
    document.getElementById("demo").innerHTML = n; 
} 
</script> 
関連する問題