sprintf problem

I am trying to format a string with a floating point specifier/value asbelow

    float flVal = 23.468;
     sprintf(buff,"The floating pointvalue is %3.2f", flVal);
     Serial.println(buff);

The result that i get is a '?' where the value shoul be.

Am I using the wrong specifier, and if so what is it ??

Many thanks !

sprintf doesn't work with float.

michinyon: sprintf doesn't work with float.

I assume that you mean that it doesn't work with Arduino C ? (asit does in "normal" C/C++) If so, that is most anoying !!

Thanks for your helpanyway !

Remittub:

michinyon: sprintf doesn't work with float.

I assume that you mean that it doesn't work with Arduino C ? (asit does in "normal" C/C++)

Yes, because the code in library about this features, is very big. You can use dtostr(). If you search in previous threads in Programming you can find many info. http://forum.arduino.cc/index.php?topic=103935.0

http://www.gammon.com.au/forum/?id=12153#trap6

Remittub: I assume that you mean that it doesn't work with Arduino C ? (asit does in "normal" C/C++) If so, that is most anoying !!

"Normal" C usually has megabytes of memory to play with these days, unlike the Arduino.

I’ve got round the problem …

    // sprintf(g_chMsg,"Float flItem = %5.2lf  <",flItem);
    byte byIntPart = (byte)flItem;
    byte byFractPart = (byte)(flItem - byIntPart)*100;
    sprintf(g_chMsg,"Zone %d temperature is %d.%d deg C", byZoneNum, byIntPart,byFractPart);

A bit messy,but it works !!

A bit messy,but it works !!

Until you try that with flItem = 1.05.

Change the format specifiers to %d.%02d, so that there are always exactly 2 digits after the decimal point.

PaulS:

A bit messy,but it works !!

Until you try that with flItem = 1.05.

Change the format specifiers to %d.%02d, so that there are always exactly 2 digits after the decimal point.

You beat me to it - just found that !! (Well spotted)