esp-open-sdk icon indicating copy to clipboard operation
esp-open-sdk copied to clipboard

printf and snprintf does not work for float or double variable

Open puppies opened this issue 5 years ago • 1 comments

When i use "snprintf" in my program on freeRTOS, i find it does not work properly. So i tried to print the float variable out to check the problem.

printf("temperature: %f\n", 22.5);

But i got these below.

temperature:

Is it due to the toolchain? What can i do to solve this problem? Much appreciated.

puppies avatar Aug 09 '18 10:08 puppies

You need to do something like this.

float temperature = 22.5; int t = temperature*10; printf("temperature: %d.%d\n", t/10, t%10);

kriegste avatar Aug 13 '18 19:08 kriegste