How to add the Percent Symbol in php computing

Computing the total price and discount price of an item

Page 1 of 1

4 Replies - 8724 Views - Last Post: 14 March 2009 - 07:42 PM Rate Topic: -----

#1 fallen0ne09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 09

How to add the Percent Symbol in php computing

Posted 14 March 2009 - 12:08 AM

I have this project and i cant get the proper output on this code.....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div align="center"><?php
			$discount = $_POST['discount'];
			$payable = 100 - $discount%;
			$amount = 100;
			$change = $amount - $payable;
				echo ("Grand total: 100"."<br>");
				echo ("Amount Payable :   $payable"."<br>");
				echo ("Change : $change"."<br>");
				?>
				 </div>
</body>
</html>


with this one.....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p>Orange 20</p>
<p>Apple 5</p>
<p>Mango 25</p>
<p>Strawberry 50</p>
<p>_____________</p>
<p>100</p>
<form id="form1" name="form1" method="post" action="compute.php">
  <label>Discount %
  <input type="text" name="discount" />
  </label>
  <br />
  <input type="submit"  />
</form>
<p> </p>
</body>
</html>


i really dont know what to do......

Is This A Good Question/Topic? 0
  • +

Replies To: How to add the Percent Symbol in php computing

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6877
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: How to add the Percent Symbol in php computing

Posted 14 March 2009 - 12:20 AM

View Postfallen0ne09, on 14 Mar, 2009 - 01:08 AM, said:

i really dont know what to do......

What exactly isn't working? Outputting a percent sign, or math/functionality?
Was This Post Helpful? 0
  • +
  • -

#3 fallen0ne09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 09

Re: How to add the Percent Symbol in php computing

Posted 14 March 2009 - 12:26 AM

View Postno2pencil, on 13 Mar, 2009 - 11:20 PM, said:

View Postfallen0ne09, on 14 Mar, 2009 - 01:08 AM, said:

i really dont know what to do......

What exactly isn't working? Outputting a percent sign, or math/functionality?

its the math functionality...... i can get the percent sign out... but not the function of it... for example.... 100 - 25%.... is equal to....
Was This Post Helpful? 0
  • +
  • -

#4 Jarv   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 11-March 09

Re: How to add the Percent Symbol in php computing

Posted 14 March 2009 - 12:31 AM

I believe your problem is that you can't use the % sign as part of a variable name in PHP.

View Postfallen0ne09, on 13 Mar, 2009 - 11:26 PM, said:

its the math functionality...... i can get the percent sign out... but not the function of it... for example.... 100 - 25%.... is equal to....


1.00 = 100%

so,

25% = .25

so in your case

discount = 100 * 0.25

payable would then be

payable = fullAmount - discount

the above is just psuedo-code btw

This post has been edited by Jarv: 14 March 2009 - 12:33 AM

Was This Post Helpful? 0
  • +
  • -

#5 fallen0ne09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 09

Re: How to add the Percent Symbol in php computing

Posted 14 March 2009 - 07:42 PM

View PostJarv, on 13 Mar, 2009 - 11:31 PM, said:

I believe your problem is that you can't use the % sign as part of a variable name in PHP.

View Postfallen0ne09, on 13 Mar, 2009 - 11:26 PM, said:

its the math functionality...... i can get the percent sign out... but not the function of it... for example.... 100 - 25%.... is equal to....


1.00 = 100%

so,

25% = .25

so in your case

discount = 100 * 0.25

payable would then be

payable = fullAmount - discount

the above is just psuedo-code btw


yes.. but what if we are only allowed whole numbers..... like 100 - 20%.... is there any formula for that? and we are using the post method in forms.....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1