round number with js
Round a number to two decimal places.
code
var rounded = Math.round(num * 100) / 100;
demo
Result...
demo code
<p><input type='text' id='rval' value='16.67894562346'></p> <p><pre id='rounded_result'>Result...</pre></p> <script> function round_val() { var val = $("#rval").val(); var rounded = Math.round(val * 100) / 100; $("#rounded_result").html(rounded); console.log(rounded); } </script> <p><button class='btn btn-dark' onclick='round_val();'>Round It</button></p>