money

package
v1.52.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2019 License: MIT Imports: 5 Imported by: 0

README

money

GoDoc

Package money represents money values with no loss in precision and without rounding errors.

Install
import (
	"libs.altipla.consulting/money"
)
Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using make gofmt.

Running tests

Run the tests:

make test
License

MIT License

Documentation

Overview

Package money represents money values with no loss in precision and without rounding errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Money

type Money struct {
	// contains filtered or unexported fields
}

Money represents a monetary value

func New

func New() *Money

New creates a new instance with a zero value.

func NewFromCents

func NewFromCents(cents int64) *Money

NewFromCents creates a new instance with a cents value.

func Parse

func Parse(s string) (*Money, error)

Parse a string to create a new money value. It can read `XX.YY` and `XX,YY`. An empty string is parsed as zero.

func (*Money) Add

func (m *Money) Add(other *Money) *Money

Add two money values together and returns the result.

func (*Money) AddTaxPercent

func (m *Money) AddTaxPercent(tax int64) *Money

AddTaxPercent adds a percentage of the price to itself.

func (*Money) Cents

func (m *Money) Cents() int64

Cents returns the value with cents precision (2 decimal places) as a number.

func (*Money) Display added in v1.52.0

func (m *Money) Display(currency string) string

Display formats the money value with a specific currency.

func (*Money) Div

func (m *Money) Div(other *Money) *Money

Div divides two money values and returns the result.

func (*Money) Format

func (m *Money) Format(prec int) string

Format the money value with a specific decimal precision.

func (*Money) IsZero

func (m *Money) IsZero() bool

IsZero returns true if there is no money.

func (*Money) LessThan

func (m *Money) LessThan(other *Money) bool

LessThan returns true if a money value is less than the other.

func (*Money) Mul

func (m *Money) Mul(n int64) *Money

Mul multiplies the money value n times and returns the result.

func (*Money) Sub

func (m *Money) Sub(other *Money) *Money

Sub subtracts two money values and returns the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL