From 49b65f87130fbe95de3134b2aa4e4775b5cee338 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 e75d6ff..74b7c58 100644 --- a/currency.go +++ b/currency.go @@ -244,7 +244,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 45c5fd0..76bf447 100644 --- a/money_test.go +++ b/money_test.go @@ -804,6 +804,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 {