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