Jump to content

Having trouble with a % calculation


mcmuney

Recommended Posts

I'm using this math code:

$stake=number_format(($mem_tot_gold/$tot_gold)*100,2);

 

1,895,462/157,657,698 = .64 (should be 1.2)

449,055/157,657,698 = 285.99 (should be .28)

 

I'd done a echo on $mem_tot_gold and $tot_gold, which are showing the right numbers. Any idea what I'm doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/
Share on other sites

The values of the variables clearly are not what you think they are when the calculation occurs.  Everything else is fine.

 


$mem_tot_gold = 1895462;
echo "mem_tot_gold: $mem_tot_gold\n";
$tot_gold = 157657698;
echo "tot_gold: $tot_gold\n";
$stake = number_format(($mem_tot_gold/$tot_gold)*100,2);
echo "$stake\n";

 

PHP 5.3.1 (cli) (built: Nov 20 2009 18:18:28) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
[david@benji ~]$ php -f pmath.php
mem_tot_gold: 1895462
tot_gold: 157657698
1.20

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.