Note that there are some explanatory texts on larger screens.

plurals
  1. PODividing variables in PHP rounding
    primarykey
    data
    text
    <p>I have a simple calculator script for making calculations of facebook insights.</p> <p>There is a function in my script called fb_growth where I pass two arguments in: one for the current month's data ($moc) and one for the previous month's data ($mop) and I am trying to find the growth percentage (positive or negative) between the 2. Here is my function script:</p> <pre><code>//Growth Calculator Function function fb_growth($moc, $mop) { if($moc&gt;=$mop) { $grp = ($moc/$mop); $grf = ($grp - 1); return $grf; } else if($moc&lt;$mop) { $grp = ($mop/$moc); $grf = (1 - $grp); return $grf; } } </code></pre> <p>The values I enter in are coming from a form that the user fills out. In this particular case, the numbers passed in are <code>fb_growth($fbfi1, $fbfi2);</code> where $fbfi1 equals the string '1719223' and $fbfi2 equals the string '1859867'. In this case, $moc is less than $mop, so 1719223 gets divided by 1859867, which should return 1.08180672315, but instead it returns 1, which then gets subtracted by 1 to get 0. What I want to end up with is '-.08180672315', which would be my growth percentage, but I cannot get it to give me this outcome. If I <code>echo ("1859867"/ "1719223");</code> then I get 1.08180672315, but when the strings are held in the variables and I <code>echo ("$fbfi2" / "$fbfi1");</code> then I get 1. </p> <p>I tried settype() to a double and an int for $grf and for both $fbfi1 &amp; 2 and same result. If I set $grf as a global and echo gettype(), it will give me the double or the int, but I still get the same value: 0. Is there something I can adjust in my php settings for this, or is there something wrong with my setup? I can't find any documentation. Help is MUCH appreciated, thank you!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload