go_currency

package module
v0.0.0-...-bf5e299 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2014 License: BSD-2-Clause Imports: 4 Imported by: 15

README

Summary

This utility software package contains functions and objects to help you write better Golang code faster.

Installation

go get github.com/go-goodies/go_currency

License

This project is licensed under a Simplified BSD license. Please read the LICENSE file.

Documentation

Index

Constants

View Source
const FnParseUSD = "ParseUSD"

Variables

View Source
var ErrRange = errors.New("value out of range")

ErrRange indicates that a value is out of range for the target type.

Functions

This section is empty.

Types

type CurrencyError

type CurrencyError struct {
	Func   string // the failing function (ParseUSD, parseEUR, ...)
	Amount string // the input
	Err    error  // the reason the conversion failed (ErrRange, ErrSyntax)
}

A CurrencyError records a failed currency conversion.

func CurrencyErrorFn

func CurrencyErrorFn(fn, str string) *CurrencyError

func (*CurrencyError) Error

func (e *CurrencyError) Error() string

type USD

type USD struct {
	Numerator   int
	Denominator int
}

func ParseUSD

func ParseUSD(priceStr string) (amountUSD USD, err error)

func (USD) Add

func (usd1 USD) Add(usd2 USD) (amountUSD USD, err error)

func (USD) Multiply

func (usd1 USD) Multiply(multiplier int) (amountUSD USD, err error)

func (USD) String

func (usd USD) String() string

func (USD) Subtract

func (usd1 USD) Subtract(usd2 USD) (amountUSD USD, err error)

func (USD) ToCents

func (usd USD) ToCents() int

func (USD) ToString

func (usd USD) ToString() string

Helper to convert USD to string, ex: s.Equal(item1PriceUSD.ToString(), "250.00")

Jump to

Keyboard shortcuts

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