diff --git a/decimal.go b/decimal.go index 914e704..7a67c8c 100644 --- a/decimal.go +++ b/decimal.go @@ -844,10 +844,9 @@ func (d Decimal) RoundBank(places int32) Decimal { // 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. +// available: 5, 10, 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 @@ -859,20 +858,6 @@ func (d Decimal) RoundCash(interval uint8) Decimal { iVal = twentyInt case 10: iVal = tenInt - case 15: - if d.exp < 0 { - // TODO: optimize and reduce allocations - orgExp := d.exp - dOne := New(10^-int64(orgExp), orgExp) - d2 := d - d2.exp = 0 - if d2.Mod(fiveDec).Equal(Zero) { - d2.exp = orgExp - d2 = d2.Sub(dOne) - d = d2 - } - } - iVal = tenInt case 25: iVal = fourInt case 50: @@ -880,7 +865,7 @@ func (d Decimal) RoundCash(interval uint8) Decimal { case 100: iVal = oneInt default: - panic(fmt.Sprintf("Decimal does not support this Cash rounding interval `%d`. Supported: 5, 10, 15, 25, 50, 100", interval)) + panic(fmt.Sprintf("Decimal does not support this Cash rounding interval `%d`. Supported: 5, 10, 25, 50, 100", interval)) } dVal := Decimal{ value: iVal, diff --git a/decimal_bench_test.go b/decimal_bench_test.go index ff9ce68..d77c275 100644 --- a/decimal_bench_test.go +++ b/decimal_bench_test.go @@ -119,16 +119,6 @@ func BenchmarkDecimal_RoundCash_Five(b *testing.B) { } } -func BenchmarkDecimal_RoundCash_Fifteen(b *testing.B) { - const want = "6.30" - for i := 0; i < b.N; i++ { - val := New(635, -2) - if have := val.StringFixedCash(15); have != want { - b.Fatalf("\nHave: %q\nWant: %q", have, want) - } - } -} - func Benchmark_Cmp(b *testing.B) { decimals := DecimalSlice([]Decimal{}) for i := 0; i < 1000000; i++ { diff --git a/decimal_test.go b/decimal_test.go index 10b350a..43a51bf 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -1565,14 +1565,6 @@ func TestDecimal_RoundCash(t *testing.T) { {"3.95", 10, "4.00"}, {"395", 10, "395"}, - {"6.42", 15, "6.40"}, - {"6.39", 15, "6.40"}, - {"6.35", 15, "6.30"}, - {"6.36", 15, "6.40"}, - {"6.349", 15, "6.30"}, - {"6.30", 15, "6.30"}, - {"666", 15, "666"}, - {"3.23", 25, "3.25"}, {"3.33", 25, "3.25"}, {"3.53", 25, "3.50"}, @@ -1608,7 +1600,7 @@ func TestDecimal_RoundCash_Panic(t *testing.T) { defer func() { if r := recover(); r != nil { if have, ok := r.(string); ok { - const want = "Decimal does not support this Cash rounding interval `231`. Supported: 5, 10, 15, 25, 50, 100" + const want = "Decimal does not support this Cash rounding interval `231`. Supported: 5, 10, 25, 50, 100" if want != have { t.Errorf("\nWant: %q\nHave: %q", want, have) }