Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: F***ing sprintf rounding - how does it work?

by swampyankee (Parson)
on Sep 04, 2012 at 01:08 UTC ( #991525=note: print w/replies, xml ) Need Help??

in reply to F***ing sprintf rounding - how does it work?

There are actually standards regarding how rounding should be done, e.g. (which is probably not universally followed) and ISO 717-1:1996. On the other hand, since floating point numbers are not real numbers (they're a subset of rational numbers), there will be times when sprintf will round the value it's given correctly, but the value that it gets is not correct, depending on how well the floating point library is written (some are much better than others) and the details of the computations being done

I've had to deal with hand-rolled rounding solutions (so that rounded numbers would add up to an integral value). You may have to roll your own rounding subroutine if you've got specific requirements.

Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

  • Comment on Re: F***ing sprintf rounding - how does it work?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991525]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-07-23 00:42 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (458 votes). Check out past polls.