Building a calculator and I'm implementing cube roots and square roots, but when reversed by squaring them or cubing them respectively, it is off by a very small, but it is noticeable and ugly in the calculator when there are several zeros and a 1 after it. Any way to prevent this, but still make the calculator accurate.
function click22() {
if (vi === 0) {
reactant = Math.sqrt(reactant);
} else if (vi !== 0 && tn === 0) {
reactant2 = Math.sqrt(reactant2);
} else if (vi !== 0 && tn !== 0) {
reactantspec = Math.sqrt(reactantspec);
}
}
function click23() {
if (vi === 0) {
reactant = Math.cbrt(reactant);
} else if (vi !== 0 && tn === 0) {
reactant2 = Math.cbrt(reactant2);
} else if (vi !== 0 && tn !== 0) {
reactantspec = Math.cbrt(reactantspec);
}
}
if (vi === 0 && reactant != "0"){
document.getElementById('result').innerHTML = reactant;
} else if (vi > 1 && reactant2 != "" && tx === 0) {
document.getElementById('result').innerHTML = reactant2;
} else if (vi > 1 && tx > 0) {
document.getElementById('result').innerHTML = reactantspec;
}
}