mcmuney Posted January 20, 2011 Share Posted January 20, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/ Share on other sites More sharing options...
parino_esquilado Posted January 20, 2011 Share Posted January 20, 2011 $mem_tot_gold = 449005; $tot_gold = 157657698; $stake=number_format(($mem_tot_gold/$tot_gold)*100,2); echo $stake; Copy and paste this, there is no reason that it shouldn't work tbh. Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162310 Share on other sites More sharing options...
Muddy_Funster Posted January 20, 2011 Share Posted January 20, 2011 Guys - who told you that you to multiply by 100 when working out a percantage? Try (tot_gold/100)*mem_tot_gold Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162407 Share on other sites More sharing options...
litebearer Posted January 20, 2011 Share Posted January 20, 2011 multiplying by 100 IS correct. Try 20/100 - ans .2 then when you multiply by 100 you get 20 another 37/74 - and .5 then x 100 you get 50 Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162454 Share on other sites More sharing options...
parino_esquilado Posted January 20, 2011 Share Posted January 20, 2011 Muddy_Funster did you fail math? haha Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162617 Share on other sites More sharing options...
gizmola Posted January 20, 2011 Share Posted January 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162668 Share on other sites More sharing options...
sasa Posted January 21, 2011 Share Posted January 21, 2011 try $stake=number_format((str_replace(',', '', $mem_tot_gold)/str_replace(',', '', $tot_gold))*100,2); Quote Link to comment https://forums.phpfreaks.com/topic/225042-having-trouble-with-a-calculation/#findComment-1162841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.