-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Swedish/Cash rounding fixes #63
Performance and allocations not that good but can be optimized later. RoundCash aka Cash/Penny/öre rounding rounds decimal to a specific interval. The amount payable for a cash transaction is rounded to the nearest multiple of the minimum currency unit available. The following intervals are available: 5, 10, 15, 25, 50 and 100; any other number throws a panic. 5: 5 cent rounding 3.43 => 3.45 10: 10 cent rounding 3.45 => 3.50 (5 gets rounded up) 15: 10 cent rounding 3.45 => 3.40 (5 gets rounded down) 25: 25 cent rounding 3.41 => 3.50 50: 50 cent rounding 3.75 => 4.00 100: 100 cent rounding 3.50 => 4.00 For more details: https://en.wikipedia.org/wiki/Cash_rounding BenchmarkDecimal_RoundCash/five-4 1000000 1918 ns/op 1164 B/op 30 allocs/op BenchmarkDecimal_RoundCash/fifteen-4 300000 4331 ns/op 2940 B/op 74 allocs/op
- Loading branch information
1 parent
ad668bb
commit 78079cf
Showing
2 changed files
with
226 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters