function to get percentage in JavaScript and return decimal value -
i have javascript function (see below). return whole number, works when inputted whole number. when inputted decimal value doesn't work.
what should handle decimal value?
function calc() { var license=parseint(document.getelementbyid("license").value); var service=parseint(document.getelementbyid("service").value); var amount=parseint(license)+parseint(service); var mult=service*(parseint(document.getelementbyid("preterms").value) / 100); var mult1=service*(parseint(document.getelementbyid("blueterms").value) / 100); var mult2=service*(parseint(document.getelementbyid("configterms").value) / 100); document.getelementbyid("amount").value = amount; document.getelementbyid("pre").value = mult; document.getelementbyid("blue").value = mult1; document.getelementbyid("config").value = mult2; }
thanks in advance.
since working decimal values need use parsefloat instead of parseint
ex:
function calc() { var license = parsefloat(document.getelementbyid("license").value); var service = parsefloat(document.getelementbyid("service").value); var amount = parsefloat(license) + parsefloat(service); var mult = service * (parsefloat(document.getelementbyid("preterms").value) / 100); var mult1 = service * (parsefloat(document.getelementbyid("blueterms").value) / 100); var mult2 = service * (parsefloat(document.getelementbyid("configterms").value) / 100); document.getelementbyid("amount").value = amount; document.getelementbyid("pre").value = mult; document.getelementbyid("blue").value = mult1; document.getelementbyid("config").value = mult2; }
Comments
Post a Comment