Percentage of a number

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
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

Percentage of a number

Post by mccommunity »

OK I know as soon as I post this I am going to realize how to do it and feel like an idiot.. but here it goes. How do I get 90% of a number with php. Say the $x variable is 100 $x=100; I want $y to be 90% of this $y=90 how do I do this? Thanks.
Owe Blomqvist
Forum Commoner
Posts: 33
Joined: Wed Oct 16, 2002 2:27 pm

Post by Owe Blomqvist »

Well, I would do it like this:

Code: Select all

<?php
$x = 100;
$y = 90%$x;
?>
or like this:

Code: Select all

<?php
$x = 100;
$y = $x*0.9;
?>
Since 0.9 is the decimal value of 90%.
A 110% would be 1.1... You get the picture. :)
Last edited by Owe Blomqvist on Tue Jul 08, 2003 4:13 pm, edited 2 times in total.
boii
Forum Newbie
Posts: 2
Joined: Tue Jul 08, 2003 3:38 pm

Post by boii »

Code: Select all

$y = $x * .9;
echo $y;


cheers.
ken
Post Reply