Jump to content

Really Simple Calculator Problems


markduce

Recommended Posts

Hello,

 

I'm a PHP coder, but my client is getting me out of my comfort zone by doing a bit of javascript.

 

I've got basic functionality set up, but I'm just coming across one issue. The thing they want is a simple percentage calculator, where someone enters a value, a percentage and the site then performs calculations based on these values.

 

It's all working fine, except when you actually physically write a percentage sign. I'm looking for some way of stripping out percentage signs. I tried the replace() function, but that just stopped the calculator working. Any advice appreciated, here's my code:

 

function calculate()
  {
a=Number(document.getElementById("edit-gpcalculatorcost").value); 
b=Number(document.getElementById("edit-gpcalculatorpercentage").value); 
b3=b;
b2=b3/100;
c=a/(1-b2);  
c2=Math.round(c*100)/100;
c3=c2*1.2;
c4=Math.round(c3*100)/100;





document.getElementById("edit-gpcalculatortotal").value=c4; 
  }

 

 

Link to comment
https://forums.phpfreaks.com/topic/259695-really-simple-calculator-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.