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

The calculation precision (16) is sometimes not enough

bojanz opened this issue · comments

Right now all amount methods use the same calculation precision:

	ctx := apd.BaseContext.WithPrecision(16)

It is possible for that precision to not be enough, for example when dealing with amounts larger than a math.MaxInt64.

Discovered in #7.

A possible solution is to always use 39 digits of precision, matching decimal128, but that can impose a performance penalty for the majority use case (where 16 digits is enough), so we probably want to switch based on a.number.Coeff.IsInt64().