0

i want to get percentage with max of 2 decimals not more than that. im getting output like this Total Score is 26.666666666666668 %

desired output 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;
    }
Swapna
  • 403
  • 3
  • 6
  • 24

1 Answers1

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>
Mukund Thakkar
  • 1,225
  • 14
  • 19