mpaland / printf

Tiny, fast, non-dependent and fully loaded printf implementation for embedded systems. Extensive test suite passing.
MIT License
2.47k stars 452 forks source link

Siginificant-digits-to-precision transition made invalid by rounding #124

Open eyalroz opened 2 years ago

eyalroz commented 2 years ago

If we sprintf(buffer,"%#.3g", 99.99);, we get 100.0 - with 4 significant digits - while we should be getting 100., with 3 significant digits.

This is because, initially, we find the power of 10 to be 2; then we translate significant digits to precision, setting the precision to 1. But after this happens, we perform rounding with precision 1, so that the power of 10 becomes 3...