snprintf() prints garbage floats with newlib nano
问题 I am running a bare metal embedded system with an ARM Cortex-M3 (STM32F205). When I try to use snprintf() with float numbers, e.g.: float f; f = 1.23; snprintf(s, 20, "%5.2f", f); I get garbage into s . The format seems to be honored, i.e. the garbage is a well-formed string with digits, decimal point, and two trailing digits. However, if I repeat the snprintf , the string may change between two calls. Floating point mathematics seems to work otherwise, and snprintf works with integers, e.g.: