Page 1 of 1

Percentage of a number

Posted: Tue Jul 08, 2003 3:45 pm
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.

Posted: Tue Jul 08, 2003 4:04 pm
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. :)

Posted: Tue Jul 08, 2003 4:04 pm
by boii

Code: Select all

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


cheers.
ken