Doing maths in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Darkside
Forum Commoner
Posts: 43
Joined: Wed Oct 30, 2002 4:18 pm

Doing maths in PHP

Post by Darkside »

I know you can download loads of voting polls etc but I wanted to make my own one. just very small but I hit a problem soon as I started.

The first thing I tryed to do was find out 1% off a given total.

Code: Select all

<?
$total = "200";
$p1 = "$total / 100";
echo "$p1"
?>
I was hoping that it would do 200 dived 100 and it would echo the answer. its not as easy as I hoped.
Any help would me nice. just so I can get this started thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try:

Code: Select all

$total = 200; 
$p1 = $total/100; 
echo $p1;
Mac
decoy1
Forum Commoner
Posts: 50
Joined: Fri Feb 21, 2003 1:33 pm
Location: St. Louis

Post by decoy1 »

You have a few syntax errors. Semicolon in wrong place, double quotes around $total / 100 (that makes it a string), etc.

This is what it should look like

Code: Select all

$total = '200'; 
$p1 = $total / 100; 
echo $p1;
This isn't going to give you 1% either, but thats easy enough to figure.

Here is a link to a thread on another board that will help you out.
http://www.sitepointforums.com/showthre ... adid=54074
Post Reply