Repository navigation
Add runtime rates and registry-aware decoding for AnyMoney - #16
Merged
Merged
Conversation
The rounding page said that the product amount × n uses 128 bits. It uses 192 bits, so it cannot overflow before the division. The page also named ErrZeroDenominator, which does not exist. Div and NewFactor return ErrDivisionByZero for a zero divisor. Signed-off-by: ayn <ayn.khatib@gmail.com>
Convert works only with Money[T] and Rate[Base, Quote], so a program that gets the currencies of a rate at run time, for example from a rate feed, could not convert an AnyMoney. AnyRate holds the base and the quote currencies with the exact rate. NewAnyRate and ParseAnyRate use the same rules as NewRate and ParseRate. AnyMoney.Convert returns ErrCurrencyMismatch if the value is not in the base currency of the rate. Rate.Any and AsRate change between the two rate types. Signed-off-by: ayn <ayn.khatib@gmail.com>
ParseAnyMoney, AnyMoney.UnmarshalJSON and AnyMoney.ScanColumns find the currency code only in currency.Default(). A program that keeps custom currencies in a separate registry, for example for each tenant, had to decode the code and the amount itself. ParseAnyMoneyIn, UnmarshalJSONIn and ScanColumnsIn take the registry. They return ErrUnknownCurrency if the registry is nil or does not have the code. The functions without a registry use currency.Default(), as before. Signed-off-by: ayn <ayn.khatib@gmail.com>
Nothing calls int128.mulPow10 since Money.Scan stopped accepting int64, so the lint job fails with "func int128.mulPow10 is unused". Signed-off-by: ayn <ayn.khatib@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix two errors in docs/rounding-and-overflow.md: the product uses 192 bits, and ErrZeroDenominator does not exist.
Add AnyRate and AnyMoney.Convert, so AnyMoney converts with a rate whose currencies are known only at run time.
Add ParseAnyMoneyIn, UnmarshalJSONIn and ScanColumnsIn, which find the currency code in a given registry.