Click to See Complete Forum and Search --> : PHP: calculation formular problem


Symbiot
July 20th, 2010, 05:07 AM
Hi

I have a math. formular which needs some tweaking:


$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?

PeejAvery
July 20th, 2010, 08:32 AM
What exactly is this formula supposed to do? If it's not working 100% of the time, then the formula is not 100% correct!

Symbiot
July 20th, 2010, 11:29 AM
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?