# Calculating results in 0 (zero) (Solved)

Nothing special codewise I think?
If I declare all variables from long to float same result.
In the real code ValueIn is the only changing variable.
But the subsitute with a fixed figure for ValueIn does not give a correct value other then 0
If I calculate by calculator I get an other value then 0. >:(
What is the hickup?
I looked through some forum entries about calculating and Arduino but could not find the enlighting lines to solve the issue.
Any help in the right direction would be swell.

Paco

``````float LoadA;
float ValueA;
float ValueB;
float ValueIn;
float ValueOut;

void setup()
{
Serial.begin(9600);
Serial.println("Test");
ValueA = 282;
ValueB = 4266;
ValueIn = 1000;
ValueOut = 0;
}

void loop()
{
//ValueOut = ((LoadB - LoadA) / (ValueB - ValueA)) * ((ValueIn) - ValueA) + LoadA // formula to calculate force with 2 know weight values 0 and 1229 grams
ValueOut = ((1229 - 0) / (4266 - 282)) * ((1000) - 282) + 0;
Serial.println(ValueOut);
delay(100);
}
``````

The integer calculation 1229/(4266-282) will be 0. If you want it done in floating point use decimal points:

1229.0/(4266.0 - 282.0)

``````  ValueOut = ((1229 - 0) / (4266 - 282)) * ((1000) - 282) + 0;
``````

is all integer.
Either cast to float, or express it as

``````ValueOut = ((1229.0 - 0) / (4266.0 - 282.0)) * ((1000.0) - 282.0) + 0;
``````

Awol,

``````ValueOut = ((1229.0 - 0) / (4266.0 - 282.0)) * ((1000.0) - 282.0) + 0;
``````

was the ticket.
Learned something today again.

Thanks both for quick quidance.

Paco