I am trying to create a simple app where any inputted number is rounded to the nearest tenth. A user inputs a number into the field, clicks submit, and it outputs the rounded number.
For example, 5.678 is inputted, 5.7 is returned.
Any help is appreciated.
<!DOCTYPE html>
<html>
<body>
<input type="number" id="b6" placeholder="Liters" name="name" maxlength="100">
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var m = document.getElementById("b6").value;
var n = m.toFixed(1);
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>