CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Posts
    9

    PHP: calculation formular problem

    Hi

    I have a math. formular which needs some tweaking:

    Code:
    $row->res_no3 = (($row->input_no3 - $row->e_no3)/$row->perc_no3*100)*($tvolume/1000)/$row->dose_week;
    Now it works fine.. but.. if e_no3 is higher than input_no3 it doesn't just result in '0' or null, it "starts from '0' again... meaning:

    if
    input_no3 = 10
    &
    e_no3 = 11

    it goes below zero, and just displays the value for:

    input_no3 = 1
    e_no3 = 0

    does that make sense? or am I babbling?

    it goes into the negative numbers, and show that result.. just without the negative notation '-'

    What can be done to prevent this?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP: calculation formular problem

    What exactly is this formula supposed to do? If it's not working 100% of the time, then the formula is not 100% correct!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2010
    Posts
    9

    Re: PHP: calculation formular problem

    Hi

    It's a nutrient calculator..
    If I set


    input_no3 = 10

    e_no3 = 10

    then the result should be 0. and any number that e_no3 contains that is higher than input_no3 should result in 0.

    unfortunately it gives a result different than 0.. and when e_no3 is higher than input_no3 it gives the negative result. so lets say

    input_no3 = 10

    e_no3 = 10

    should = 0


    ===

    input_no3 = 15

    e_no3 = 10

    should = 5

    ====

    input_no3 = 10

    e_no3 = 15

    should = 0 (but would give -5 (but displayed as 5) )

    ===

    The formula is fine... in excel, on a calculator, and everywhere else.. but not in php.. I am thinking that php (or the program code) does not take negative numbers into account?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured