0

Following is my script which I am trying to find solution for it. But I actually this function return round of ANS: 2. Eg. If input value is greater than 2.01 then result will be 3. I know round function is not help me to get this kind of answer. please help me to fix this issue.

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

<p id="demo"></p>
<script>
    function myFunction() {
        document.getElementById("demo").innerHTML = Math.round(2.01); 
    } 
</script>
2
  • If answer helps you please mark as accepted for further use Commented Jun 15, 2016 at 12:53
  • 2
    I'm voting to close this question as off-topic because user asking about javascript
    – Amit Bera
    Commented Jun 20, 2016 at 13:58

2 Answers 2

1

Use below code:

<script>
  num = Math.ceil(2.01);
  alert(num);
</script>
0

There you go

<p id="demo"></p>
<script>
        function myFunction() {
            document.getElementById("demo").innerHTML = Math.ceil(2.01 * 10) / 10; //2.00
            //test greater value
            document.getElementById("demo").innerHTML = Math.ceil(2.16 * 10) / 10; //2.2
        } 
</script>

Not the answer you're looking for? Browse other questions tagged or ask your own question.