I want to round up a decimal value in JavaScript. I need functionality something like below :
if decimal value is grater than or equal to 25 then i want to round up a value by plus one.
eg. if value = 5.56789 then new value should be 6
I know using if condition it is possible.
I have done using if condition like below :
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the fixed number.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var num = 5.24389;
var n = num.toFixed(2)
var num_arr = n.split('.');
var newval = num_arr[0];
if(num_arr[1] >= 25)
{
newval++;
}
document.getElementById("demo").innerHTML = newval;
}
</script>
</body>
</html>
But i don't want to use any conditions.
So is there any JavaScript function which do like my example?
Any help would be appreciated!!