cur

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeKZT = "KZT"
	CodeUSD = "USD"
	CodeRUB = "RUB"
	CodeEUR = "EUR"
)

Variables

View Source
var (
	ErrBadCurrency = errors.New("bad currency")
)
View Source
var (
	ErrBadMinorUnit = errors.New("bad currency minor unit")
)

Functions

This section is empty.

Types

type Currency

type Currency uint32

Currency is a currency type

const (
	// Unknown currency
	Unknown Currency = iota
	// KZT - Kazakhstan Tenge
	KZT
	// USD - U.S. Dollar
	USD
	// RUB - Russian Ruble
	RUB
	// EUR - Euro
	EUR
)

func ParseCurrency

func ParseCurrency(s string) Currency

ParseCurrency returns Currency or Unknown.

func (Currency) ISO4217

func (c Currency) ISO4217() *ISO4217

ISO4217 returns currency ISO4217 standard info or nil

func (Currency) MinorUnits

func (c Currency) MinorUnits() MinorUnits

MinorUnits returns minor units of currency or MinorUnitsUnknown.

func (Currency) String

func (c Currency) String() string

String return code of currency

USD.String() // "USD"

func (Currency) Validate

func (c Currency) Validate() error

Validate validates currency. In case of invalid currency returns ErrBadCurrency.

type ISO4217

type ISO4217 struct {
	Name           string
	AlphabeticCode string
	NumericCode    uint16
	MinorUnits     MinorUnits
}

type MinorUnits

type MinorUnits uint8

MinorUnits is a type for currency's minor units

const (
	MinorUnitsUnknown MinorUnits = 255
	MinorUnits0       MinorUnits = 0
	MinorUnits2       MinorUnits = 2
	MinorUnits3       MinorUnits = 3
)

func (MinorUnits) String

func (m MinorUnits) String() string

String returns string value of minor units

func (MinorUnits) Validate

func (m MinorUnits) Validate() error

Validate validates minor unit, on error returns ErrBadMinorUnit.

func (MinorUnits) Zero

func (m MinorUnits) Zero() string

Zero returns zero value for minor unit.

Example: MinorUnits(2).Zero // "00"

Jump to

Keyboard shortcuts

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