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

Add support for the accounting formatter style (negative amounts in parenthesis)

jarreds opened this issue · comments

Eg ($1.00) == -$1.00

What is the use case/context in which you would use the parenthesis format?

We are using the library within a core ledger system, and we would like to use the standard accounting format to represent debit/credit balances:

image

Becomes:

image

That's a valid use case, and one worth supporting.

Implementation notes:

  • We need to add an accountingPattern to the currencyFormat struct
  • We need to parse the "accounting" pattern in readFormat() in gen.go
  • We should omit the accounting pattern if it's the same as the standard one, and have the formatter know how to fallback.
  • The Formatter needs a Style field which can be "standard" or "accounting" and which influences which pattern is picked by getPattern(). We want to introduce an enum type for the Style like we did for RoundingMode and Display, but currency.Style is not distinctive enough. Perhaps FormatterStyle?

We'll want to do the CLDR v44 update first, it looks like it has relevant fixes (for the accounting patterns in various locales, such as the ones inheriting from es-419)

@jarreds I have a PR up now, please test and provide feedback.