Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.