bojanz / currency

Currency handling for Go.

Home Page:https://pkg.go.dev/github.com/bojanz/currency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle minor amount values

Kunde21 opened this issue · comments

Financial APIs use minor values in order to avoid any invalid amounts or ambiguous encoding.

As this library stands, it is unable to handle parsing amounts from or writing amounts to a string in minor units. ToMinorUnits risks overflow attacks on int64 datatype.

Let's add a NewFromMinorUnits() which parallels ToMinorUnits(), and use strings for both.

How does that sound?

I'm experimenting with a type currency.Minor that embeds an amount, so the encoding/decoding can be handled properly, as well.

Fixed in e18a432.

Followup: #11