I'm currently setting up a few formula calculators. On the one I have this formula:
vc=ds*π.ns/60000
with this script:
<script>
(function () {
function calculateVc(ds, ns) {
return (ds * 3.14159265359 * ns / 60000);
}
var Vc = document.getElementById("VC");
if (Vc) {
Vc.onsubmit = function () {
this.Vc.value = calculateVc(this.ds.value, this.ns.value);
return false;
};
}
}());
</script>
Which works perfectly. And then I have the reverse formula: ns=vc*60000/(ds*π) with this script:
<script>
(function () {
function calculateNs(ds, vc) {
return (vc * 60000 / ds * 3.14159265359);
}
var Ns = document.getElementById("Ns");
if (Ns) {
Ns.onsubmit = function () {
this.ns.value = calculateNs(this.ds.value, this.vc.value);
return false;
};
}
}());
</script>
Which doesn't work as required. Reusing the first result in a backward formula gives different results than expected. I suppose it's either a formatting error or a typo.