Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
Issues using printf with floats.
Hallo everyone, I've recently ran aground with some trouble using printf to output floats. We're talking the typical:
printf("Inter-event interval:\t%.6f\n", IEI);
outputting something like:
<[ |U Ã5 @ $ô ÿ? € c 0.0 <[0.000100
Where the 0.000100 is the correct value, but everything before has been garbled.
My questions are: 1) Why is this happening? 2) Why has this started happening only very recently with no changes in the code? I've been operating this code for almost a year without a problem. 3) How can this be solved most elegantly?
Thanks.
1 Answer
8 years, 6 months ago.
Not sure if the format for a %f is correct with nothing to the left of the decimal.
Can you try
printf("Inter-event interval:\t%7.6f\n", IEI);
as an experiment?