You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fpmoney.Amount serializes values to JSON as a floating point amount, and a currency code like this:
{
"amount": 128.45,
"currency": "ARS"
}
That is used in frontends and persisted in databases as a floating point number.
Other currency packages serialize the amount as a string instead, to avoid conversions and lost of precision. For example:
{
"amount": "128.45",
"currency": "ARS"
}
What do you think of having a global option or be customized by the format string stored under the "json" key (or a money key) in the struct field's tag:
type Invoice struct {
TotalAmount fpmoney.Amount `json:"totalAmount,asString"`
}
I can provide a PR.
The text was updated successfully, but these errors were encountered:
better not to use json tags. to avoid reflection and gencode.
global option (package level var) - good option. please proceed draft PR if you want!
please add fuzz/unit test for this too if you make PR
I also need to think how this package can nicely provide both versions (JSON string vs JSON number) at same time. Should we have new type? Same type name but sub-package? 🤔
One thing that may be odd here though — people use string for serialising numbers (money) to avoid using parsing, conversions (float/int/bigint) and arithmetics codebases. Here in this package we exposing parsing and arithmetics. People who use string as number in their JSON may not want to use fpmoney. So use-case may not be a strong.
However, this is interesting extension to this package!
The
fpmoney.Amount
serializes values to JSON as a floating point amount, and a currency code like this:That is used in frontends and persisted in databases as a floating point number.
Other currency packages serialize the amount as a string instead, to avoid conversions and lost of precision. For example:
What do you think of having a global option or be customized by the format string stored under the "json" key (or a money key) in the struct field's tag:
I can provide a PR.
The text was updated successfully, but these errors were encountered: