Skip to content

Google APIs money representation #151

@riverwoodland

Description

@riverwoodland

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions