Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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. http://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules (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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991525]
help
Chatterbox?
LanX is not affraid of Trump ...
LanX ... me is scared of people voting for Trumps
[erix]: until good old Putin lobs a bomb on Berlin :)
[Your Mother]: “I’m afraid of Americans…”
[Your Mother]: “No one needs anyone / They don’t even just pretend…”
[erix]: they've stuck nuclear missiles in Kaliningrad - they can just reach Berlin :)
[LanX]: naaah! Putin wouldn't nuke all the Russians in Berlin
[Your Mother]: Putin is a bad guy but he’s not that kind of bad guy. (Who would launch.)
[erix]: fortunately, Putin seems to be ill -- or at least, they're building a hospital for him and his cronies in Moscow

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-01-20 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.