Skip to content

Fix AnyMoney currency checks and extend AnyMoney, JSON and SQL support - #14

Merged
khatibomar merged 1 commit into
mainfrom
fix-review-findings
Oct 10, 2026
Merged

khatibomar merged 1 commit into
mainfrom
fix-review-findings

Conversation

@khatibomar

Copy link
Copy Markdown
Owner

Fix: AnyMoney As/Add/Sub/Cmp compare minor units too, so a same-code currency with other minor units no longer changes the value.
Add AnyMoney Mul/Div/MulFactor/RoundCash/Abs/Neg/Allocate/Sign and ScanColumns; JSON null is a no-op; Money JSON code is case-insensitive; Scan accepts exact float64 (SQLite).
Breaking (beta): Validate/ErrValidation become InRange; Allocate accepts zero ratios and ErrNegativeOrZeroRatios becomes ErrInvalidRatios.

- As, Add, Sub and Cmp of AnyMoney compare the minor units and the code.
  Before, a currency with the same code and other minor units changed
  the value without an error, for example 1.0000 USD became USD 100.00.
- Add Mul, Div, MulFactor, RoundCash, Abs, Neg, Allocate, Sign,
  IsPositive and IsNegative to AnyMoney.
- Add AnyMoney.ScanColumns to read an amount column and a currency
  code column with database/sql.
- UnmarshalJSON of Money and AnyMoney does not change the value for a
  JSON null. The currency code of Money JSON is not case-sensitive.
- Scan accepts a float64 with at most 15 significant digits, as SQLite
  returns for a NUMERIC column.
- Replace Validate and ErrValidation with InRange, which returns a bool.
- Allocate accepts zero ratios if one ratio is positive.
  ErrNegativeOrZeroRatios is now ErrInvalidRatios.
- Document the int64 limit of the terms of Rate and Factor.

Signed-off-by: ayn <ayn.khatib@gmail.com>
@khatibomar
khatibomar merged commit caa232b into main Oct 10, 2026
7 checks passed
@khatibomar
khatibomar deleted the fix-review-findings branch October 10, 2026 01:52
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.

1 participant