can somebody help me to solve this problem? I'm trying to get a difference between a lower tolerance and an upper tolerance. I've found a site that gives me the .js calculation for the upper and lower tolerance, it also gives me the maximum and minimum diameter, but I also want to get the diference between those results. I've tried to find all over internet but failed at finding something. Here is the link to the code and .js files that i'm using.
https://jsfiddle.net/my974Ljh/1/
I have another code iqual to this one, with one more script. But this script gives me the result I want but I have to insert manualy the inputs.
<script type="text/javascript">
function id(el) {
return document.getElementById( el );
}
function total( un, diamx ) {
return parseFloat(un.replace(',', '.'), 10) - parseFloat(diamx.replace(',', '.'), 10);
}
window.onload = function() {
id('diamn').addEventListener('keyup', function() {
var result = total( this.value , id('diamx').value );
id('total').value = String(result.toFixed(3)).formatMoney();
});
id('diamx').addEventListener('keyup', function(){
var result = total( id('diamn').value , this.value );
id('total').value = String(result.toFixed(3)).formatMoney();
});
}
String.prototype.formatMoney = function() {
var v = this;
if(v.indexOf('.') === -1) {
v = v.replace(/([\d]+)/, "$1,00");
}
v = v.replace(/([\d]+)\.([\d]{1})$/, "$1,$200");
v = v.replace(/([\d]+)\.([\d]{2})$/, "$1,$2");
v = v.replace(/([\d]+)([\d]{3}),([\d]{2})$/, "$1.$2,$3");
return v;
};
</script>
Hope you can help me with this one. I know that I can simplify the code but I'm trying to solve one problem at a time.
Thank you so much.