Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kotaroyamazaki
Copy link
Contributor

@kotaroyamazaki kotaroyamazaki commented Nov 8, 2022

NewFromFloat did not support lowercase currency codes because it used getCurrencyByCode.
As same as New(), fix to use newCurrency(code).get() instead.

Fixed GetCurrency to be case-insensitive so that it wouldn't fail at upper case.

And Add test case.

money.go Outdated
// Always rounding trailing decimals down.
func NewFromFloat(amount float64, currency string) *Money {
currencyDecimals := math.Pow10(GetCurrency(currency).Fraction)
currencyDecimals := math.Pow10(newCurrency(currency).get().Fraction)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think on letting GetCurrency to return currency in a case insensitive manner?

newCurrecy().get() seems a little convolute to do the same.

Copy link
Contributor Author

@kotaroyamazaki kotaroyamazaki Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good one. (in my way , GetCurrency still fails with uppercase codes.)
Fixed GetCurrency to be case-insensitive

686ba37

@kotaroyamazaki kotaroyamazaki changed the title fix NewFromFloat to use newCurrency instead of GetCurrency Fixed GetCurrency to be case-insensitive Nov 11, 2022
@Rhymond Rhymond merged commit 49b65f8 into Rhymond:master Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants