Rounding – Simple, but when it comes to the financial domain, it is more complex than it sounds! Rounding can be especially problematic when multiple rounds of calculations are involved, such as in compound interest calculations or currency conversions. A small error in calculations can lead to significant discrepancies over time.
We faced unique challenges in a billing and invoicing project to keep utmost precision and still present the user with significant digits. We decided to do all calculations with high precision and round only in the UI and invoices, which was an acceptable solution until we ran into more complex issues.
How do we distribute $100 equally to three persons without rounding issues?
If you want to equally distribute $100 to three different persons without rounding issues, you can use the following method:
- Divide the total amount by the number of people you want to distribute it to. In this case, $100 divided by 3 equals $33.33
- Multiply the result by the number of people to get the final amount each person should receive. In this case, $33.33 x 3 = $99.99
- Subtract $99.99 from the total amount and give it to the last person. In this case, $0.01
By following this method, you ensure that each person receives $33.33 (100/3) and that the total amount is distributed without any rounding issues. This is a commonly used method in the financial domain. It’s important to note that this method will only work if the total amount is divisible by the number of people without a remainder. If the total amount is not divisible, it may not be possible to distribute it without rounding errors.
How do we decide on the last person?
Round Robin? Alphabetical? Again, this is tricky if we need to regenerate or redo the calculation later. It is prevalent in billing and invoice to revise an invoice in case of an error, and we need to set some standards.
Common Rounding Issues
One common issue in rounding is known as “rounding error.” This occurs when a number is rounded to a certain number of decimal places, but the original number contains more decimal places than the rounded number. For example, if a number like 0.1 is rounded to the nearest whole number, the result would be 0. However, the actual value of 0.1 is slightly more than 0; over time, this slight difference can add up to a significant error.
Another area for improvement with rounding is that it can create discrepancies between different systems or platforms. For example, suppose a financial calculation is performed on a system that uses different rounding rules than another. In that case, the results may be different, even if the inputs are the same.
To avoid these issues, it’s essential to use consistent rounding rules across all systems and platforms and to be aware of the potential for rounding errors in calculations. Additionally, it’s a good practice to use more decimal places in calculations to minimise the impact of rounding errors.
The rule of thumb when it comes to rounding is that if you are dealing with large sums of money and rounding to the nearest decimal does affect materiality, then do not round. The rounding is acceptable so long as the rounded amounts will not mislead the reported information.
Different Algorithms
There are numerous algorithms to round the numbers, each one with different trade-offs to get rid of the unwanted digits. Round-toward-nearest, Round-half-up, half-down, half-even, half-odd, ceiling, floor, towards-zero, away-from-zero, round-up, round-down and even truncate is used in rounding.
- Arithmetic Rounding: This is the most common rounding algorithm, and it is based on the “round to nearest” rule. It rounds a number to the nearest whole number, with numbers exactly halfway between two whole numbers rounded to the nearest even number.
- Bankers Rounding: This algorithm is similar to arithmetic rounding, but it is used mainly in financial systems. It rounds a number to the nearest whole number, with numbers exactly halfway between two whole numbers rounded to the nearest even number. It’s also known as round to nearest even.
- Ceiling Rounding: This algorithm always rounds a number up to the nearest whole number. This can be useful when it’s crucial to ensure that a value is never less than a certain number.
- Floor Rounding: This algorithm always rounds a number down to the nearest whole number. This can be useful in situations where it’s important to ensure that a value is never greater than a certain number.
- Truncation: This algorithm simply cuts off the decimal part of a number without rounding. This can be useful in situations where precision is not important, and the final result should always be less than or equal to the original number.
The choice of a rounding algorithm can significantly impact the final result, especially when working with large data sets or in financial calculations. DotNET uses banker’s rounding by default.
Standards in Rounding!
Does rounding numbers in the financial domain have a common standard? There exists some standard when it comes to currency conversion.
- International Financial Reporting Standards (IFRS): IFRS is a set of accounting standards developed by the International Accounting Standards Board (IASB). It includes guidelines on rounding financial numbers in financial statements, such as the requirement to round amounts to the nearest whole number or the nearest multiple of 10.
- Generally Accepted Accounting Principles (GAAP): GAAP is a set of accounting standards used in the United States. It includes similar guidelines on rounding financial numbers as IFRS and requires that any rounding errors should be immaterial and insignificant.
- International Organization for Standardization (ISO): ISO has a standard for Rounding off numerical values, which is ISO 80000-1:2009. It provides guidelines on rounding numerical values in general and not specific to the finance domain, but it’s widely used in financial systems.
- The Federal Reserve Board (FRB): The FRB, the central banking system of the United States, has guidelines on rounding financial numbers for bank reporting and financial statement preparation.
- The European Central Bank (ECB): The ECB, the central banking system of the European Union, has similar guidelines on rounding financial numbers as the FRB.
Data types to Store Rounded Digits!
The decimal data type is the best choice to store currency in the financial domain because it allows for high precision and can handle decimal numbers, which is important for monetary values. Never use binary floating-point types for storing currency. Because floating-point numbers have a limited number of digits, they cannot represent all real numbers accurately: when there are more digits than the format allows, the leftover ones are omitted – the number is rounded. If you really need your results to add up exactly, especially when you work with money: use a special decimal datatype. If you have no decimal data type available, an alternative is to work with integers.
It’s crucial to ensure that the decimal data type is implemented to handle the range of expected currency values, it’s compatible with the systems and platforms, and it can take the currency formatting and localisation. By using consistent rounding rules and being mindful of the potential for errors, businesses can minimise the impact of rounding on their financial calculations.
Author: Bharath Krishna
Bharath Krishna is a Technical lead at Founding Minds with 8+ years of experience in the finance domain. In his current role at FoundingMinds Software Private Limited, he is responsible for the technical direction and delivery of dotNET-based solutions. He is proficient in the latest .NET technologies such as DotNet Core, EF Core, Worker service etc. He is always looking for ways to improve the efficiency and effectiveness of the development process. He has experience with AWS, Azure & GCP. He is committed to staying current with the latest trends and technologies and is always open to exploring new approaches to system design.
Reference: https://floating-point-gui.de/