money

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: MIT Imports: 4 Imported by: 1

README

money

Basic money representation in Go with no loss in precision.

Install

go get github.com/altipla-consulting/money

Documentation

GoDoc

Contributing

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

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 (money *Money) Add(other *Money) *Money

Add two money values together and returns the result.

func (*Money) AddTaxPercent

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

AddTaxPercent adds a percentage of the price to itself.

func (*Money) Cents

func (money *Money) Cents() int64

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

func (*Money) Div

func (money *Money) Div(other *Money) *Money

Div divides two money values and returns the result.

func (*Money) Format

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

Format the money value with a specific decimal precision.

func (*Money) IsZero

func (money *Money) IsZero() bool

IsZero returns true if there is no money.

func (*Money) LessThan

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

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

func (*Money) Markup

func (money *Money) Markup(tax int64) *Money

Markup adds a percentage with decimals of the price to itself. The percentage should be pre-multiplied by 100 to avoid floating point issues.

func (*Money) Mul

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

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

func (*Money) Sub

func (money *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