money

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2016 License: MIT Imports: 5 Imported by: 0

README

go-money

godoc reference Build Status codecov License

Small Golang library to parse and print money amounts.

Install
go get gopkg.in/mvader/go-money.v1
Usage
a, err := money.Parse("3500000 eur")
if err != nil {
  log.Fatal(err)
}

fmt.Println(a) // prints 3.5M €

fmt.Println(money.NewAmount(3500, "€")) // prints 3.5K €

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	// Quantity is the quantity of the amount.
	Quantity float64
	// Currency is the currency of the amount.
	Currency string
}

Amount represents a quantity of money with a currency.

func NewAmount

func NewAmount(q float64, currency string) *Amount

NewAmount creates a new amount with the given quantity and currency.

func Parse

func Parse(text string) (*Amount, error)

Parse returns an Amount of money with quantity and currency (if identified) and an error.

func ParseComma

func ParseComma(text string) (*Amount, error)

ParseComma parses the amount of money in the text with "," instead of "." as decimal separator.

func (Amount) String

func (a Amount) String() string

String returns the money as string in the format "[QUANTITY](.DECIMAL)(M|k)( CURRENCY)".

func (Amount) StringBefore

func (a Amount) StringBefore() string

StringBefore returns the money as string in the format "[CURRENCY][QUANTITY](.DECIMAL)(M|k)".

func (Amount) StringComma

func (a Amount) StringComma() string

StringComma returns the money as string in the format "[QUANTITY](,DECIMAL)(M|k)( CURRENCY)".

Jump to

Keyboard shortcuts

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