Appendix H. Rounding Algorithms 101
Introduction
We all remember being taught the concept of rounding in our younger years at school. Common problems involved monetary values, such as rounding some amount like $26.19 to the nearest dollar (which would be 26 dollars, in the case of this example). However, although this may seem simple at a first glance, there’s a lot more to rounding than might at first meet the eye …
One key aspect of rounding that is easy to overlook (because it’s so obvious) is that it involves transforming some quantity from a greater precision to a lesser precision. As we’ve just seen, for example, rounding a more precise value like $26.19 to the nearest dollar results in 26 dollars, which is less precise.
This means that ...
Get Bebop to the Boolean Boogie, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.