math calculation issue

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

math calculation issue

Post by itsmani1 »

Code: Select all

$percent1 = $percent / 100;
$percent1 = $price * $percent1;
when $percent1 = 24.02
and $price = 12
the above expressgives me result zero in $percent1
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Where did you define $price and $percent.... the expression alone is zero if they haven't been defined correctly :?

Code: Select all

$price = 12;
$percent = 24.02;

$percent1 = $percent / 100;
$percent1 = $price * $percent1;
echo $percent1;
2.8824
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: math calculation issue

Post by Chris Corbyn »

itsmani1 wrote: when $percent1 = 24.02
Is that a typo? $percent1 is what you are calculating and if that is defined instead of $percent that explains the problem ;)
Post Reply