Skip to content

Add money comparisson #112

@totemcaf

Description

@totemcaf

There are several methods to compare two Money object but there is no Money.Compare(Money) function.

The proposal is to add a Compare function for Money.

// Compare returns an integer comparing two Money objects
// If Money objects are of different currency, an ErrCurrencyMismatch is returned.
// If both objects are for same currency, their amounts are compared.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (m *Money) Compare(om *Money) int {
    if err := m.assertSameCurrency(om); err != nil {
        return false, err
    }

    return m.compare(om), nil
}

I'll provide a PR.

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