Re: Should %d round?

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...

Further to a recent post, I would like to solicit general opinion on whether

    printf(1,"%d\n",3.9999999) 

should print 3 (as it does now) or 4?

I'm of the opinion that %d should display the integer portion of the number. If you need it rounded, do that explicitly.

    printf(1,"%d\n",round(3.9999999)) 

However, I'll consider adding a rounding qualifier for the format() function, which is used by the formatting write routines. Something like ...

    writefln("[r]",3.55) --> 4 
    writefln("[r10]",3.55) --> 3.6 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu