Rounding an Intermediate or Final Result
Rounding before combining values can change the result. The correct stage depends on the intended numerical or domain contract.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace three fractions
Rounding each 1.4 to a whole unit gives one, then the sum of three is three. Adding first gives 4.2 and rounding gives four. Truncation and rounding supply the one-value rule.
Choose the policy deliberately
A billing contract may round each line or the full total. A numerical algorithm can retain additional precision in intermediates. Decimal amount representation explains one domain with explicit rules.[1][2]
Compare a rounded intermediate sum with final rounding
Three values each equal 0.34. In exact decimal arithmetic their sum is 1.02, which rounds to 1.0 at one decimal. Rounding each first yields three values of 0.3 and a total of 0.9. The choice of rounding point changes the reported amount. See decimal input and money.
Raw: .34 + .34 + .34 = 1.02 → 1.0
Early rounding: .3 + .3 + .3 = .9
Difference between policies: .1
Document exceptions such as required row rounding
A specification may require rounding each line item to its smallest unit. In that case use the required policy and test the aggregate. Otherwise preserve adequate working precision and round the final display deliberately.