percentages of over 1000

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
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

percentages of over 1000

Post by bradles »

For some strange reason if I try and get 10 % of my session variable $x when it is over 1000 I end up with the answer being 0.1 when it should be 100.

I have tried with amounts under 1000 like 975 and it returns 97.5 as it should but the minute i go over 1000 i get 0.1.

Stupid thing is that I can do it in a test script and everything seems fine.

Code: Select all

$x = 1650.00;
$y = 0.1;
$result = $x * $y;
echo "x*y = $result";

Does anyone know what this could be? I have spent about 3 hours trying to figure this out and still no luck.

Brad
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Dont <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> yourself off wondering why it doesnt work and use a different method:

Code: Select all

$result = ($x/100)*10;
$result = $x/10;
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,

your script echos "165" as it should. Can't redo your error.

djot
-
Post Reply