Go Down

Topic: Converting float to char (Read 172 times) previous topic - next topic

MoonMonkey

Hey there,

I have a Arduino Uno and I just want to convert a float to char. My code is

-------------
char hum[6];

int n = sprintf(hum, "%f", 56.98);

Serial.println(hum);
Serial.println(n);
--------


And it just prints:

?
1


I don't understand what I'm doing wrong.

sprintf(hum, "%d", 356);

works normally.

Help is very welcome! :)

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

KeithRB

sprintf() does not support floats to save space. try dtostrf().

AVR docs on dtostrf()

Go Up