I have a sensor read-out that's an int, but I need to do some division on it, so I want to cast it to float. But somehow it always returns 0.
So I wrote a little test snippet which if I understand the float reference correctly should return the correct value, but it also only returns 0:
int a = 250;
float fl = (float) a * 1.0;
sprintf(printBuffer,"a = %d , fl = %d \n",a, fl);
Serial.println(printBuffer);
The output is "a = 250 , fl = 0" - what am I doing wrong?
(This is the example used in the reference:)
int x;
int y;
float z;
x = 1;
y = x / 2; // y now contains 0, ints can't hold fractions
z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)