currency

package module
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 1 Imported by: 7

README

currency

This package generates structs containing all the up-to-date ISO4217 currency codes and minor units, along with a very simple validator.

Data is graciously provided by:

Usage:

package main

func main() {
	// Validation of codes.
	ok := currency.Valid("ABC")
	if !ok {
		// whatever you need.
	}

	// easy to get the values
	fmt.Println(currency.USD.Code())
	// Output: USD

	fmt.Println(currency.USD.MinorUnit())
	// Output: 2
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AED currency struct
	AED = Currency{/* contains filtered or unexported fields */}
	// AFN currency struct
	AFN = Currency{/* contains filtered or unexported fields */}
	// ALL currency struct
	ALL = Currency{/* contains filtered or unexported fields */}
	// AMD currency struct
	AMD = Currency{/* contains filtered or unexported fields */}
	// ANG currency struct
	ANG = Currency{/* contains filtered or unexported fields */}
	// AOA currency struct
	AOA = Currency{/* contains filtered or unexported fields */}
	// ARS currency struct
	ARS = Currency{/* contains filtered or unexported fields */}
	// AUD currency struct
	AUD = Currency{/* contains filtered or unexported fields */}
	// AWG currency struct
	AWG = Currency{/* contains filtered or unexported fields */}
	// AZN currency struct
	AZN = Currency{/* contains filtered or unexported fields */}
	// BAM currency struct
	BAM = Currency{/* contains filtered or unexported fields */}
	// BBD currency struct
	BBD = Currency{/* contains filtered or unexported fields */}
	// BDT currency struct
	BDT = Currency{/* contains filtered or unexported fields */}
	// BGN currency struct
	BGN = Currency{/* contains filtered or unexported fields */}
	// BHD currency struct
	BHD = Currency{/* contains filtered or unexported fields */}
	// BIF currency struct
	BIF = Currency{/* contains filtered or unexported fields */}
	// BMD currency struct
	BMD = Currency{/* contains filtered or unexported fields */}
	// BND currency struct
	BND = Currency{/* contains filtered or unexported fields */}
	// BOB currency struct
	BOB = Currency{/* contains filtered or unexported fields */}
	// BOV currency struct
	BOV = Currency{/* contains filtered or unexported fields */}
	// BRL currency struct
	BRL = Currency{/* contains filtered or unexported fields */}
	// BSD currency struct
	BSD = Currency{/* contains filtered or unexported fields */}
	// BTN currency struct
	BTN = Currency{/* contains filtered or unexported fields */}
	// BWP currency struct
	BWP = Currency{/* contains filtered or unexported fields */}
	// BYN currency struct
	BYN = Currency{/* contains filtered or unexported fields */}
	// BZD currency struct
	BZD = Currency{/* contains filtered or unexported fields */}
	// CAD currency struct
	CAD = Currency{/* contains filtered or unexported fields */}
	// CDF currency struct
	CDF = Currency{/* contains filtered or unexported fields */}
	// CHE currency struct
	CHE = Currency{/* contains filtered or unexported fields */}
	// CHF currency struct
	CHF = Currency{/* contains filtered or unexported fields */}
	// CHW currency struct
	CHW = Currency{/* contains filtered or unexported fields */}
	// CLF currency struct
	CLF = Currency{/* contains filtered or unexported fields */}
	// CLP currency struct
	CLP = Currency{/* contains filtered or unexported fields */}
	// CNY currency struct
	CNY = Currency{/* contains filtered or unexported fields */}
	// COP currency struct
	COP = Currency{/* contains filtered or unexported fields */}
	// COU currency struct
	COU = Currency{/* contains filtered or unexported fields */}
	// CRC currency struct
	CRC = Currency{/* contains filtered or unexported fields */}
	// CUC currency struct
	CUC = Currency{/* contains filtered or unexported fields */}
	// CUP currency struct
	CUP = Currency{/* contains filtered or unexported fields */}
	// CVE currency struct
	CVE = Currency{/* contains filtered or unexported fields */}
	// CZK currency struct
	CZK = Currency{/* contains filtered or unexported fields */}
	// DJF currency struct
	DJF = Currency{/* contains filtered or unexported fields */}
	// DKK currency struct
	DKK = Currency{/* contains filtered or unexported fields */}
	// DOP currency struct
	DOP = Currency{/* contains filtered or unexported fields */}
	// DZD currency struct
	DZD = Currency{/* contains filtered or unexported fields */}
	// EGP currency struct
	EGP = Currency{/* contains filtered or unexported fields */}
	// ERN currency struct
	ERN = Currency{/* contains filtered or unexported fields */}
	// ETB currency struct
	ETB = Currency{/* contains filtered or unexported fields */}
	// EUR currency struct
	EUR = Currency{/* contains filtered or unexported fields */}
	// FJD currency struct
	FJD = Currency{/* contains filtered or unexported fields */}
	// FKP currency struct
	FKP = Currency{/* contains filtered or unexported fields */}
	// GBP currency struct
	GBP = Currency{/* contains filtered or unexported fields */}
	// GEL currency struct
	GEL = Currency{/* contains filtered or unexported fields */}
	// GHS currency struct
	GHS = Currency{/* contains filtered or unexported fields */}
	// GIP currency struct
	GIP = Currency{/* contains filtered or unexported fields */}
	// GMD currency struct
	GMD = Currency{/* contains filtered or unexported fields */}
	// GNF currency struct
	GNF = Currency{/* contains filtered or unexported fields */}
	// GTQ currency struct
	GTQ = Currency{/* contains filtered or unexported fields */}
	// GYD currency struct
	GYD = Currency{/* contains filtered or unexported fields */}
	// HKD currency struct
	HKD = Currency{/* contains filtered or unexported fields */}
	// HNL currency struct
	HNL = Currency{/* contains filtered or unexported fields */}
	// HTG currency struct
	HTG = Currency{/* contains filtered or unexported fields */}
	// HUF currency struct
	HUF = Currency{/* contains filtered or unexported fields */}
	// IDR currency struct
	IDR = Currency{/* contains filtered or unexported fields */}
	// ILS currency struct
	ILS = Currency{/* contains filtered or unexported fields */}
	// INR currency struct
	INR = Currency{/* contains filtered or unexported fields */}
	// IQD currency struct
	IQD = Currency{/* contains filtered or unexported fields */}
	// IRR currency struct
	IRR = Currency{/* contains filtered or unexported fields */}
	// ISK currency struct
	ISK = Currency{/* contains filtered or unexported fields */}
	// JMD currency struct
	JMD = Currency{/* contains filtered or unexported fields */}
	// JOD currency struct
	JOD = Currency{/* contains filtered or unexported fields */}
	// JPY currency struct
	JPY = Currency{/* contains filtered or unexported fields */}
	// KES currency struct
	KES = Currency{/* contains filtered or unexported fields */}
	// KGS currency struct
	KGS = Currency{/* contains filtered or unexported fields */}
	// KHR currency struct
	KHR = Currency{/* contains filtered or unexported fields */}
	// KMF currency struct
	KMF = Currency{/* contains filtered or unexported fields */}
	// KPW currency struct
	KPW = Currency{/* contains filtered or unexported fields */}
	// KRW currency struct
	KRW = Currency{/* contains filtered or unexported fields */}
	// KWD currency struct
	KWD = Currency{/* contains filtered or unexported fields */}
	// KYD currency struct
	KYD = Currency{/* contains filtered or unexported fields */}
	// KZT currency struct
	KZT = Currency{/* contains filtered or unexported fields */}
	// LAK currency struct
	LAK = Currency{/* contains filtered or unexported fields */}
	// LBP currency struct
	LBP = Currency{/* contains filtered or unexported fields */}
	// LKR currency struct
	LKR = Currency{/* contains filtered or unexported fields */}
	// LRD currency struct
	LRD = Currency{/* contains filtered or unexported fields */}
	// LSL currency struct
	LSL = Currency{/* contains filtered or unexported fields */}
	// LYD currency struct
	LYD = Currency{/* contains filtered or unexported fields */}
	// MAD currency struct
	MAD = Currency{/* contains filtered or unexported fields */}
	// MDL currency struct
	MDL = Currency{/* contains filtered or unexported fields */}
	// MGA currency struct
	MGA = Currency{/* contains filtered or unexported fields */}
	// MKD currency struct
	MKD = Currency{/* contains filtered or unexported fields */}
	// MMK currency struct
	MMK = Currency{/* contains filtered or unexported fields */}
	// MNT currency struct
	MNT = Currency{/* contains filtered or unexported fields */}
	// MOP currency struct
	MOP = Currency{/* contains filtered or unexported fields */}
	// MRU currency struct
	MRU = Currency{/* contains filtered or unexported fields */}
	// MUR currency struct
	MUR = Currency{/* contains filtered or unexported fields */}
	// MVR currency struct
	MVR = Currency{/* contains filtered or unexported fields */}
	// MWK currency struct
	MWK = Currency{/* contains filtered or unexported fields */}
	// MXN currency struct
	MXN = Currency{/* contains filtered or unexported fields */}
	// MXV currency struct
	MXV = Currency{/* contains filtered or unexported fields */}
	// MYR currency struct
	MYR = Currency{/* contains filtered or unexported fields */}
	// MZN currency struct
	MZN = Currency{/* contains filtered or unexported fields */}
	// NAD currency struct
	NAD = Currency{/* contains filtered or unexported fields */}
	// NGN currency struct
	NGN = Currency{/* contains filtered or unexported fields */}
	// NIO currency struct
	NIO = Currency{/* contains filtered or unexported fields */}
	// NOK currency struct
	NOK = Currency{/* contains filtered or unexported fields */}
	// NPR currency struct
	NPR = Currency{/* contains filtered or unexported fields */}
	// NZD currency struct
	NZD = Currency{/* contains filtered or unexported fields */}
	// OMR currency struct
	OMR = Currency{/* contains filtered or unexported fields */}
	// PAB currency struct
	PAB = Currency{/* contains filtered or unexported fields */}
	// PEN currency struct
	PEN = Currency{/* contains filtered or unexported fields */}
	// PGK currency struct
	PGK = Currency{/* contains filtered or unexported fields */}
	// PHP currency struct
	PHP = Currency{/* contains filtered or unexported fields */}
	// PKR currency struct
	PKR = Currency{/* contains filtered or unexported fields */}
	// PLN currency struct
	PLN = Currency{/* contains filtered or unexported fields */}
	// PYG currency struct
	PYG = Currency{/* contains filtered or unexported fields */}
	// QAR currency struct
	QAR = Currency{/* contains filtered or unexported fields */}
	// RON currency struct
	RON = Currency{/* contains filtered or unexported fields */}
	// RSD currency struct
	RSD = Currency{/* contains filtered or unexported fields */}
	// RUB currency struct
	RUB = Currency{/* contains filtered or unexported fields */}
	// RWF currency struct
	RWF = Currency{/* contains filtered or unexported fields */}
	// SAR currency struct
	SAR = Currency{/* contains filtered or unexported fields */}
	// SBD currency struct
	SBD = Currency{/* contains filtered or unexported fields */}
	// SCR currency struct
	SCR = Currency{/* contains filtered or unexported fields */}
	// SDG currency struct
	SDG = Currency{/* contains filtered or unexported fields */}
	// SEK currency struct
	SEK = Currency{/* contains filtered or unexported fields */}
	// SGD currency struct
	SGD = Currency{/* contains filtered or unexported fields */}
	// SHP currency struct
	SHP = Currency{/* contains filtered or unexported fields */}
	// SLE currency struct
	SLE = Currency{/* contains filtered or unexported fields */}
	// SOS currency struct
	SOS = Currency{/* contains filtered or unexported fields */}
	// SRD currency struct
	SRD = Currency{/* contains filtered or unexported fields */}
	// SSP currency struct
	SSP = Currency{/* contains filtered or unexported fields */}
	// STN currency struct
	STN = Currency{/* contains filtered or unexported fields */}
	// SVC currency struct
	SVC = Currency{/* contains filtered or unexported fields */}
	// SYP currency struct
	SYP = Currency{/* contains filtered or unexported fields */}
	// SZL currency struct
	SZL = Currency{/* contains filtered or unexported fields */}
	// THB currency struct
	THB = Currency{/* contains filtered or unexported fields */}
	// TJS currency struct
	TJS = Currency{/* contains filtered or unexported fields */}
	// TMT currency struct
	TMT = Currency{/* contains filtered or unexported fields */}
	// TND currency struct
	TND = Currency{/* contains filtered or unexported fields */}
	// TOP currency struct
	TOP = Currency{/* contains filtered or unexported fields */}
	// TRY currency struct
	TRY = Currency{/* contains filtered or unexported fields */}
	// TTD currency struct
	TTD = Currency{/* contains filtered or unexported fields */}
	// TWD currency struct
	TWD = Currency{/* contains filtered or unexported fields */}
	// TZS currency struct
	TZS = Currency{/* contains filtered or unexported fields */}
	// UAH currency struct
	UAH = Currency{/* contains filtered or unexported fields */}
	// UGX currency struct
	UGX = Currency{/* contains filtered or unexported fields */}
	// USD currency struct
	USD = Currency{/* contains filtered or unexported fields */}
	// USN currency struct
	USN = Currency{/* contains filtered or unexported fields */}
	// UYI currency struct
	UYI = Currency{/* contains filtered or unexported fields */}
	// UYU currency struct
	UYU = Currency{/* contains filtered or unexported fields */}
	// UYW currency struct
	UYW = Currency{/* contains filtered or unexported fields */}
	// UZS currency struct
	UZS = Currency{/* contains filtered or unexported fields */}
	// VED currency struct
	VED = Currency{/* contains filtered or unexported fields */}
	// VES currency struct
	VES = Currency{/* contains filtered or unexported fields */}
	// VND currency struct
	VND = Currency{/* contains filtered or unexported fields */}
	// VUV currency struct
	VUV = Currency{/* contains filtered or unexported fields */}
	// WST currency struct
	WST = Currency{/* contains filtered or unexported fields */}
	// XAF currency struct
	XAF = Currency{/* contains filtered or unexported fields */}
	// XAG currency struct
	XAG = Currency{/* contains filtered or unexported fields */}
	// XAU currency struct
	XAU = Currency{/* contains filtered or unexported fields */}
	// XBA currency struct
	XBA = Currency{/* contains filtered or unexported fields */}
	// XBB currency struct
	XBB = Currency{/* contains filtered or unexported fields */}
	// XBC currency struct
	XBC = Currency{/* contains filtered or unexported fields */}
	// XBD currency struct
	XBD = Currency{/* contains filtered or unexported fields */}
	// XCD currency struct
	XCD = Currency{/* contains filtered or unexported fields */}
	// XDR currency struct
	XDR = Currency{/* contains filtered or unexported fields */}
	// XOF currency struct
	XOF = Currency{/* contains filtered or unexported fields */}
	// XPD currency struct
	XPD = Currency{/* contains filtered or unexported fields */}
	// XPF currency struct
	XPF = Currency{/* contains filtered or unexported fields */}
	// XPT currency struct
	XPT = Currency{/* contains filtered or unexported fields */}
	// XSU currency struct
	XSU = Currency{/* contains filtered or unexported fields */}
	// XTS currency struct
	XTS = Currency{/* contains filtered or unexported fields */}
	// XUA currency struct
	XUA = Currency{/* contains filtered or unexported fields */}
	// XXX currency struct
	XXX = Currency{/* contains filtered or unexported fields */}
	// YER currency struct
	YER = Currency{/* contains filtered or unexported fields */}
	// ZAR currency struct
	ZAR = Currency{/* contains filtered or unexported fields */}
	// ZMW currency struct
	ZMW = Currency{/* contains filtered or unexported fields */}
	// ZWG currency struct
	ZWG = Currency{/* contains filtered or unexported fields */}
)

Following are all the structs containing currency data

View Source
var ValidCodes = []string{}/* 179 elements not displayed */

ValidCodes is provided so that you may build your own validation against it

Functions

func Valid

func Valid(code string) bool

Valid checks if a provided code is contained inside the provided ValidCodes slice

Types

type Currency

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

Currency defines a currency containing It's code, taken from the constants above as well as it's minor units, as an integer.

func Get

func Get(code string) (*Currency, error)

Get returns a currency struct if the provided code is contained within the valid codes. Otherwise an error will be returned

func (*Currency) Code

func (c *Currency) Code() string

Code returns the currency code to the user

func (*Currency) Factor

func (c *Currency) Factor() int

Factor returns the factor by which a float should be multiplied to get back to it's smallest denomination

Example:

pence := 100.00 * currency.GBP.Factor()

func (*Currency) FactorF64

func (c *Currency) FactorF64() float64

FactorF64 returns the factor, converted to a float64

func (*Currency) FactorI64

func (c *Currency) FactorI64() int64

FactorI64 returns the factor, converted to a int64

func (*Currency) MinorUnits

func (c *Currency) MinorUnits() int

MinorUnits returns the minor unit to the user

func (*Currency) Name added in v1.7.0

func (c *Currency) Name() string

Name returns the currency name as defined in the ISO.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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