Re: Should %d round?
- Posted by DerekParnell (admin) Mar 20, 2012
- 1725 views
AJ_Oxley said...
So a workable solution would be documenting the issue as a known gotcha, rather than making changes to Euphoria?
Yes, documenting this more accurately would be a good idea.
Also consider the following ...
atom x = 3.552 printf(1, "%d\n", x) -->3 printf(1, "%.0f\n", x) -->4 printf(1, "%.1f\n", x) -->3.6 printf(1, "%.2f\n", x) -->3.55 printf(1, "%.3f\n", x) -->3.552
The documentation needs to make clear that %d will only print the integer portion of a number. If one wants the decimals to influence the output you need to use the %f code instead, specifying the required rounding location.