Jump to content

Variable calculations


Texan78
Go to solution Solved by Texan78,

Recommended Posts

Hello, I am trying to take the calculations of two variables to create a new data for a new variable. For example.....

 

LRH_calcLevel($LRH_current, $LRH_bankfull); +/- $LRH_totalDepth = $newVar 

 

Which should translate to -10.43 Ft +/- 40 = $newVar (-29.57) <----- What I want

 

Instead it is showing up as 10.43 Ft +/- 40 = $newVar (-50.43) <----- How it is displaying which is incorrect

 

Here is the code I am using. The second function is what I am trying to use to create the new variable data based on the calculations above from the data provide via XML. How can I get this to display correctly?

 

-Thanks

//Parse Lake Ray Hubbard XML Data
$site = simplexml_load_file($LRH_data);{

        $LRH_bankfull   = '435.5';
        $LRH_totalDepth = '40';
        $LRH_current    = $site->observed->datum[0]->primary;
        $LRH_vaild      = $site->observed->datum[0]->valid;
        $LRH_updated    = DATE("D, M d, g:i a", STRTOTIME($LRH_vaild));

}

//Lets calculate the lake depatures from full pool for Lake Ray Hubbard
function LRH_calcLevel($LRH_current, $LRH_bankfull)
{
    //Get float values from strings
    $LRH_current = floatval($LRH_current);
    $LRH_bankfull = floatval($LRH_bankfull);
    //Calculate the difference
    $LRH_calcLevel = $LRH_current - $LRH_bankfull;
    //Format difference to two decimal places and add 'Ft'
    $LRH_calcLevelStr = (string) number_format($LRH_calcLevel, 2) . ' Ft';
    //If vlaue is positive add a + to beginning
    if($LRH_calcLevel>0) { $LRH_calcLevelStr = '+'.$LRH_calcLevelStr; }
    //Return the calculated formatted value
    return $LRH_calcLevelStr;
}

////Lets calculate the lake percentage from full pool for Lake Ray Hubbard
$val1 = $LRH_current;
$val2 = $LRH_bankfull;

$LRH_prec = ( $val1 / $val2) * 100;

// 1 digit after the decimal point
$LRH_prec = round($LRH_prec, 1);

//Lets convert the depature from full pool for Lake Ray Hubbard
function LRH_calcDepth($LRH_calcLevelStr, $LRH_totalDepth)
{
    //Get float values from strings
    $LRH_calcDepthStr = floatval($LRH_calcLevelStr);
    $LRH_totalDepth = floatval($LRH_totalDepth);
    //Calculate the difference
    $LRH_calcDepth = $LRH_calcDepthStr - $LRH_totalDepth;
    //Format difference to two decimal places and add 'Ft'
    $LRH_calcDepthStr = (string) number_format($LRH_calcDepth, 2) . ' Ft';
    //If vlaue is positive add a + to beginning
    if($LRH_calcDepth>0) { $LRH_calcDepthStr = '+'.$LRH_calcDepthStr; }
    //Return the calculated formatted value
    return $LRH_calcDepthStr;
}

////Lets calculate the lake percentage from full pool for Lake Ray Hubbard
$val1 = LRH_calcLevel($LRH_current, $LRH_bankfull);
$val2 = $LRH_totalDepth;
Link to comment
Share on other sites

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.