From 686ba372ed2dedb756d4abc2ffcc6db83d38acf7 Mon Sep 17 00:00:00 2001 From: kotaroyamazaki Date: Tue, 8 Nov 2022 19:28:14 +0900 Subject: [PATCH] fix NewFromFloat to use newCurrency instead of GetCurrency --- currency.go | 2 +- money_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/currency.go b/currency.go index dcd07b0..869cc2f 100644 --- a/currency.go +++ b/currency.go @@ -239,7 +239,7 @@ func newCurrency(code string) *Currency { // GetCurrency returns the currency given the code. func GetCurrency(code string) *Currency { - return currencies.CurrencyByCode(code) + return currencies.CurrencyByCode(strings.ToUpper(code)) } // Formatter returns currency formatter representing diff --git a/money_test.go b/money_test.go index e336998..9e515cf 100644 --- a/money_test.go +++ b/money_test.go @@ -665,6 +665,16 @@ func TestNewFromFloat(t *testing.T) { t.Errorf("Expected currency %s got %s", EUR, m.currency.Code) } + m = NewFromFloat(12.34, "eur") + + if m.amount != 1234 { + t.Errorf("Expected %d got %d", 1234, m.amount) + } + + if m.currency.Code != EUR { + t.Errorf("Expected currency %s got %s", EUR, m.currency.Code) + } + m = NewFromFloat(-0.125, EUR) if m.amount != -12 {