Skip to content

Commit

Permalink
fix NewFromFloat to use newCurrency instead of GetCurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
kotaroyamazaki authored and Rhymond committed Jul 29, 2024
1 parent f9d20a6 commit 49b65f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions money_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49b65f8

Please sign in to comment.