Re: Should %d round?

new topic     » goto parent     » topic index » view thread      » older message » newer message
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.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu