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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access