func (m *Money) Split(n int) ([]*Money, error) {
	if n <= 0 {
		return nil, errors.New("split must be higher than zero")
	}
	a := mutate.calc.divide(m.amount, int64(n))
	ms := make([]*Money, n)
	for i := 0; i < n; i++ {
		ms[i] = &Money{amount: a, currency: m.currency}
	}
	l := mutate.calc.modulus(m.amount, int64(n)).val
	for p := 0; l != 0; p++ {
		ms[p].amount = mutate.calc.add(ms[p].amount, &Amount{1})
		l--
	}
	return ms, nil
}
Split returns slice of Money structs with split Self value in given number.
After division leftover pennies will be distributed round-robin amongst the parties.
This means that parties listed first will likely receive more pennies than ones that are listed later.
package money
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
)
var (
	UnmarshalJSON = defaultUnmarshalJSON
	MarshalJSON = defaultMarshalJSON
	ErrCurrencyMismatch = errors.New("currencies don't match")
)
func defaultUnmarshalJSON(m *Money, b []byte) error {
	data := make(map[string]interface{})
	err := json.Unmarshal(b, &data)
	if err != nil {
		return err
	}
	ref := New(int64(data["amount"].(float64)), data["currency"].(string))
	*m = *ref
	return nil
}
func defaultMarshalJSON(m Money) ([]byte, error) {
	buff := bytes.NewBufferString(fmt.Sprintf(`{"amount": %d, "currency": "%s"}`, m.Amount(), m.Currency().Code))
	return buff.Bytes(), nil
}
type Amount struct {
	val int64
}
type Money struct {
	amount   *Amount
	currency *Currency
}
func New(amount int64, code string) *Money {
	return &Money{
		amount:   &Amount{val: amount},
		currency: newCurrency(code).get(),
	}
}
func (m *Money) Currency() *Currency {
	return m.currency
}
func (m *Money) Amount() int64 {
	return m.amount.val
}
func (m *Money) SameCurrency(om *Money) bool {
	return m.currency.equals(om.currency)
}
func (m *Money) assertSameCurrency(om *Money) error {
	if !m.SameCurrency(om) {
		return ErrCurrencyMismatch
	}
	return nil
}
func (m *Money) compare(om *Money) int {
	switch {
	case m.amount.val > om.amount.val:
		return 1
	case m.amount.val < om.amount.val:
		return -1
	}
	return 0
}
func (m *Money) Equals(om *Money) (bool, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return false, err
	}
	return m.compare(om) == 0, nil
}
func (m *Money) GreaterThan(om *Money) (bool, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return false, err
	}
	return m.compare(om) == 1, nil
}
func (m *Money) GreaterThanOrEqual(om *Money) (bool, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return false, err
	}
	return m.compare(om) >= 0, nil
}
func (m *Money) LessThan(om *Money) (bool, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return false, err
	}
	return m.compare(om) == -1, nil
}
func (m *Money) LessThanOrEqual(om *Money) (bool, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return false, err
	}
	return m.compare(om) <= 0, nil
}
func (m *Money) IsZero() bool {
	return m.amount.val == 0
}
func (m *Money) IsPositive() bool {
	return m.amount.val > 0
}
func (m *Money) IsNegative() bool {
	return m.amount.val < 0
}
func (m *Money) Absolute() *Money {
	return &Money{amount: mutate.calc.absolute(m.amount), currency: m.currency}
}
func (m *Money) Negative() *Money {
	return &Money{amount: mutate.calc.negative(m.amount), currency: m.currency}
}
func (m *Money) Add(om *Money) (*Money, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return nil, err
	}
	return &Money{amount: mutate.calc.add(m.amount, om.amount), currency: m.currency}, nil
}
func (m *Money) Subtract(om *Money) (*Money, error) {
	if err := m.assertSameCurrency(om); err != nil {
		return nil, err
	}
	return &Money{amount: mutate.calc.subtract(m.amount, om.amount), currency: m.currency}, nil
}
func (m *Money) Multiply(mul int64) *Money {
	return &Money{amount: mutate.calc.multiply(m.amount, mul), currency: m.currency}
}
func (m *Money) Round() *Money {
	return &Money{amount: mutate.calc.round(m.amount, m.currency.Fraction), currency: m.currency}
}