I need to convert a float value to a string in my avr project. Therefore I tried it with the following code:
char buf[10];
float emg1 = 33.42;
sprintf(buf, "%f", emg1);
uart_puts(buf);
But the output is only a "?". I tried to change the char format from %f to %g but I only got "?".
Is there another way to simply convert float to string, or can somebody tell me where the mistake is?
sprintf(buf, "%d", 123)just to be sure that the problem is not elsewhere?-Wl,-u,vfprintf -lprintf_flt -lmhas to be enabled forfloat, as peravrdoc.sprintf(buf, "%f", emg1);is not certainly enough info to convert the string back to the samefloat. Better assprintf(buf, "%.8e", emg1);orsprintf(buf, "%.9g", emg1);with a larger buffer (about 17+).