Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google APIs money representation #151

Open
riverwoodland opened this issue Nov 13, 2024 · 0 comments
Open

Google APIs money representation #151

riverwoodland opened this issue Nov 13, 2024 · 0 comments

Comments

@riverwoodland
Copy link

riverwoodland commented Nov 13, 2024

Google has a Money type based on a unit and nano representation. It is used, for example, in the Publisher API to obtain prices of base plans.

Based on a quick research this seems to be based on a fixed-point approach of representing money and, according to the provided link, it seems to be a common way to store dollars for example.

I took a look at the documentation and couldn't find any way to create a money.Money instance from this kind of representation. Do you think it would make sense to support it? I'm imagining something like:

const (
	FixedPointSizeDeci  = 1
	FixedPointSizeCenti = 2
	FixedPointSizeMilli = 3
	FixedPointSizeMicro = 6
	FixedPointSizeNano  = 9
)

func NewFromFixedPoint(units int64, fraction int64, size uint64, code string) *money.Money

// Specifying 1.25€ using "nanos"
euros := money.NewFromFixedPoint(1, 250_000_000, money.FixedPointSizeNano, money.EUR)
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

No branches or pull requests

1 participant