I have a simple calculation, a number between 19 and 55 is in the Input and the Output shows the calculation. I cannot figure out how to control the number of decimal points. Ideally, I would like to have 1 or 2 decimal places.
Here is the code I have so far:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Output Formatting</title>
<script src="https://d3js.org/d3-format.v1.min.js"></script>
</head>
<body>
<form oninput="result.value=(-1.0797 * parseInt(a.value) * parseInt(a.value)) + (52.466 * parseInt(a.value) - 820.183)">
<input id="aa" type="number" name="a" onchange="setTwoNumberDecimal" min="19" max="55" step="0.25" value="22.00" /> <br>
<output id="polar" name="result">-</output>
</form>
</body>
</html>
I have seen some examples of D3.js being applied to control formatting, but I cannot figure out how to implement it here. The function doesn't appear to run, but I am not getting console errors:
<script>
function setTwoNumberDecimal(){
var format = d3.format(".3n");
var fname = d3.format(".3n")(document.getElementById('aa').value);
document.getElementById('polar').innerHTML = fname;
}
</script>
I also have a JS_Fiddle