Percentage of a number
Moderator: General Moderators
-
mccommunity
- Forum Commoner
- Posts: 62
- Joined: Mon Oct 07, 2002 8:55 am
Percentage of a number
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
Well, I would do it like this:
or like this:
Since 0.9 is the decimal value of 90%.
A 110% would be 1.1... You get the picture.
Code: Select all
<?php
$x = 100;
$y = 90%$x;
?>Code: Select all
<?php
$x = 100;
$y = $x*0.9;
?>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.