I've been trying to round my digits to the nearest thousandth in JavaScript for a calculator, and it has, but it still displays the decimal points which have 0 as their value in the end, but I want to limit it down to the nearest number with a value. (I want it to limit down like such: 100.000 -> 100, 948.500 -> 948.5, etc.) Is there any way to limit the extra place holders being displayed instead of displaying the 0's?
function getInputValue() {
// Selecting the input element and get its value
var y2 = document.getElementById("input1").value;
var y1 = document.getElementById("input2").value;
var x2 = document.getElementById("input3").value;
var x1 = document.getElementById("input4").value;
let total = (y2 - y1) / (x2 - x1);
total = total.toFixed(4);
};
I have already tried to use other rounding methods, but they didn't round as expected.