Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.