What am I doing wrong in this cast?

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)

Could this be a problem:

sprintf(printBuffer,"a = %d , fl = %d \n",a, fl);

First, by default, sprintf() doesn't work on floats in the Arduino environment.

Second, if it did, the format specifier would be '%f', not '%d'.

Try just Serial.print of your float variable, it should be right.

Use dtostrf() to convert it to a c-string.

Why yes, yes it is. Worked with a regular print.

Why is that? I checked http://www.cplusplus.com/reference/cstdio/sprintf/ and it didn't say anything about types?

EDIT: ah, gfvalvo answered my questions while I was typing it... cheers peoples!