currency

package
v1.51.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: AGPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error wraps errors coming from this package.
	Error = errs.Class("currency")
)

Functions

This section is empty.

Types

type MicroUnit added in v1.1.1

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

MicroUnit represents 1e-6 or one millionth of a unit of currency (e.g. one millionth of a dollar). It is used instead of a floating point type to prevent rounding errors.

var (

	// Zero is a MicroUnit representing 0.
	Zero MicroUnit
)

func MicroUnitFromDecimal added in v1.1.1

func MicroUnitFromDecimal(d decimal.Decimal) (MicroUnit, error)

MicroUnitFromDecimal returns a MicroUnit from a decimal value and returns an error if there is not enough precision.

func MicroUnitFromFloatString added in v1.1.1

func MicroUnitFromFloatString(s string) (MicroUnit, error)

MicroUnitFromFloatString parses the string from FloatString into a MicroUnit.

func NewMicroUnit added in v1.1.1

func NewMicroUnit(v int64) MicroUnit

NewMicroUnit returns a MicroUnit with v. Much like a time.Duration, a value of 1 means 1e-6 or one millionth of a unit of currency.

func (MicroUnit) Decimal added in v1.1.1

func (m MicroUnit) Decimal() decimal.Decimal

Decimal returns the a decimal form of the MicroUnit.

func (MicroUnit) FloatString added in v1.1.1

func (m MicroUnit) FloatString() string

FloatString returns a string fixed to 6 decimal places.

func (MicroUnit) MarshalCSV added in v1.1.1

func (m MicroUnit) MarshalCSV() (string, error)

MarshalCSV does the custom marshaling of MicroUnits.

func (*MicroUnit) UnmarshalCSV added in v1.1.1

func (m *MicroUnit) UnmarshalCSV(s string) (err error)

UnmarshalCSV reads the MicroUnit in CSV form.

func (MicroUnit) Value added in v1.1.1

func (m MicroUnit) Value() int64

Value returns the underlying MicroUnit value.

type USD

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

USD describes USD currency.

func Cents

func Cents(cents int) USD

Cents converts cents to USD amount.

func Dollars

func Dollars(dollars int) USD

Dollars converts dollars to USD amount.

func (USD) Add

func (usd USD) Add(b USD) USD

Add adds two usd values and returns the result.

func (USD) Cents

func (usd USD) Cents() int

Cents returns amount in cents.

func (USD) String

func (usd USD) String() string

String returns the value in dollars.

Jump to

Keyboard shortcuts

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