Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:21:43+00:00 2026-06-05T07:21:43+00:00

I have a simple calculator script for making calculations of facebook insights. There is

  • 0

I have a simple calculator script for making calculations of facebook insights.

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:

//Growth Calculator Function
function fb_growth($moc, $mop) {
    if($moc>=$mop) {
        $grp = ($moc/$mop);
        $grf = ($grp - 1);
        return $grf;
    }
    else if($moc<$mop) {
        $grp = ($mop/$moc);
        $grf = (1 - $grp);
        return $grf;
    }
}

The values I enter in are coming from a form that the user fills out. In this particular case, the numbers passed in are fb_growth($fbfi1, $fbfi2); 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 echo ("1859867"/ "1719223"); then I get 1.08180672315, but when the strings are held in the variables and I echo ("$fbfi2" / "$fbfi1"); then I get 1.

I tried settype() to a double and an int for $grf and for both $fbfi1 & 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!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:21:44+00:00Added an answer on June 5, 2026 at 7:21 am

    And the problem was… comma’s in the entry numbers!! I was inputing 123,456 instead of 123456. That’s what you get when you just carelessly copy and paste sometimes..wow. Thanks for all the help though, I learned a lot about casting!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this simple script: function paginateUsers(page){ get( _config_remote_host+'/users?page='+page,function(json){ json = JSON.parse(json); var _html
so I have a very simple script I'm writing to be a calculator so
I have coded my calculator in simple mode, I have added a button for
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple jQuery script which pushes the footer to the bottom of
I am trying to write a simple C calculator script, using only the basic
I have a simple script works fine in html. Yet in a gsp, it
I have a script, that's pretty huge for an actual simple task, because it's
I have a script, that takes the value from two select tags, and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.