iso4217

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 0 Imported by: 1

README

iso4217

GoDoc GolangCI

A Go package providing all ISO 4217 currency codes as constants of type iso4217.Currency.

For each currency the three-letter alphabetic code, the three-digit numeric code, the currency exponent and the English name are available.

The exponent for historic denominations, for which the constants are annotated as deprecated, is currently inaccurate.

Currencies can either be hardcoded using the available constants or loaded from a string using FromAlpha() and FromNumeric().

Examples

Use the constants to directly reference currencies.

rates := []struct {
    currency iso4217.Currency
    amount   float32
}{
    {iso4217.CAD, 1.30488},
    {iso4217.JPY, 110.10},
    {iso4217.CLF, 0.028043},
}

fmt.Println("Today, one United States Dollar equals;")
for _, r := range rates {
    fmt.Printf("- %.*f %s\n", r.currency.Exponent(), r.amount, r.currency.Name())
}

// Output:
// Today, one United States Dollar equals;
// - 1.30 Canadian Dollar
// - 110 Yen
// - 0.0280 Unidad de Fomento

Use FromAlpha() and FromNumeric() to load a currency from a string.

currency, _ := iso4217.FromNumeric("608") // Ignoring error for simplicity
fmt.Println(currency.Alpha(), "is the alphabetic currency code for the", currency.Name())

// Output:
// PHP is the alphabetic currency code for the Philippine Peso

Source

Documentation

Overview

Package iso4217 provides the ISO 4217 codes for the representation of currencies and funds.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Currency

type Currency uint16

Currency is a representation of a currency or fund.

const (
	ADP Currency // Deprecated: Andorran Peseta (020)
	AED          // UAE Dirham (784)
	AFA          // Deprecated: Afghani (004)
	AFN          // Afghani (971)
	ALK          // Deprecated: Old Lek (008)
	ALL          // Lek (008)
	AMD          // Armenian Dram (051)
	ANG          // Netherlands Antillean Guilder (532)
	AOA          // Kwanza (973)
	AOK          // Deprecated: Kwanza (024)
	AON          // Deprecated: New Kwanza (024)
	AOR          // Deprecated: Kwanza Reajustado (982)
	ARA          // Deprecated: Austral (032)
	ARP          // Deprecated: Peso Argentino (032)
	ARS          // Argentine Peso (032)
	ARY          // Deprecated: Peso (032)
	ATS          // Deprecated: Schilling (040)
	AUD          // Australian Dollar (036)
	AWG          // Aruban Florin (533)
	AYM          // Deprecated: Azerbaijan Manat (945)
	AZM          // Deprecated: Azerbaijanian Manat (031)
	AZN          // Azerbaijan Manat (944)
	BAD          // Deprecated: Dinar (070)
	BAM          // Convertible Mark (977)
	BBD          // Barbados Dollar (052)
	BDT          // Taka (050)
	BEC          // Deprecated: Convertible Franc (993)
	BEF          // Deprecated: Belgian Franc (056)
	BEL          // Deprecated: Financial Franc (992)
	BGJ          // Deprecated: Lev A/52 (100)
	BGK          // Deprecated: Lev A/62 (100)
	BGL          // Deprecated: Lev (100)
	BGN          // Bulgarian Lev (975)
	BHD          // Bahraini Dinar (048)
	BIF          // Burundi Franc (108)
	BMD          // Bermudian Dollar (060)
	BND          // Brunei Dollar (096)
	BOB          // Boliviano (068)
	BOP          // Deprecated: Peso boliviano (068)
	BOV          // Mvdol (984)
	BRB          // Deprecated: Cruzeiro (076)
	BRC          // Deprecated: Cruzado (076)
	BRE          // Deprecated: Cruzeiro (076)
	BRL          // Brazilian Real (986)
	BRN          // Deprecated: New Cruzado (076)
	BRR          // Deprecated: Cruzeiro Real (987)
	BSD          // Bahamian Dollar (044)
	BTN          // Ngultrum (064)
	BUK          // Deprecated: Kyat (104)
	BWP          // Pula (072)
	BYB          // Deprecated: Belarusian Ruble (112)
	BYN          // Belarusian Ruble (933)
	BYR          // Deprecated: Belarusian Ruble (974)
	BZD          // Belize Dollar (084)
	CAD          // Canadian Dollar (124)
	CDF          // Congolese Franc (976)
	CHC          // Deprecated: WIR Franc (for electronic) (948)
	CHE          // WIR Euro (947)
	CHF          // Swiss Franc (756)
	CHW          // WIR Franc (948)
	CLF          // Unidad de Fomento (990)
	CLP          // Chilean Peso (152)
	CNY          // Yuan Renminbi (156)
	COP          // Colombian Peso (170)
	COU          // Unidad de Valor Real (970)
	CRC          // Costa Rican Colon (188)
	CSD          // Deprecated: Serbian Dinar (891)
	CSJ          // Deprecated: Krona A/53 (203)
	CSK          // Deprecated: Koruna (200)
	CUC          // Peso Convertible (931)
	CUP          // Cuban Peso (192)
	CVE          // Cabo Verde Escudo (132)
	CYP          // Deprecated: Cyprus Pound (196)
	CZK          // Czech Koruna (203)
	DDM          // Deprecated: Mark der DDR (278)
	DEM          // Deprecated: Deutsche Mark (276)
	DJF          // Djibouti Franc (262)
	DKK          // Danish Krone (208)
	DOP          // Dominican Peso (214)
	DZD          // Algerian Dinar (012)
	ECS          // Deprecated: Sucre (218)
	ECV          // Deprecated: Unidad de Valor Constante (UVC) (983)
	EEK          // Deprecated: Kroon (233)
	EGP          // Egyptian Pound (818)
	ERN          // Nakfa (232)
	ESA          // Deprecated: Spanish Peseta (996)
	ESB          // Deprecated: "A" Account (convertible Peseta Account) (995)
	ESP          // Deprecated: Spanish Peseta (724)
	ETB          // Ethiopian Birr (230)
	EUR          // Euro (978)
	FIM          // Deprecated: Markka (246)
	FJD          // Fiji Dollar (242)
	FKP          // Falkland Islands Pound (238)
	FRF          // Deprecated: French Franc (250)
	GBP          // Pound Sterling (826)
	GEK          // Deprecated: Georgian Coupon (268)
	GEL          // Lari (981)
	GHC          // Deprecated: Cedi (288)
	GHP          // Deprecated: Ghana Cedi (939)
	GHS          // Ghana Cedi (936)
	GIP          // Gibraltar Pound (292)
	GMD          // Dalasi (270)
	GNE          // Deprecated: Syli (324)
	GNF          // Guinean Franc (324)
	GNS          // Deprecated: Syli (324)
	GQE          // Deprecated: Ekwele (226)
	GRD          // Deprecated: Drachma (300)
	GTQ          // Quetzal (320)
	GWE          // Deprecated: Guinea Escudo (624)
	GWP          // Deprecated: Guinea-Bissau Peso (624)
	GYD          // Guyana Dollar (328)
	HKD          // Hong Kong Dollar (344)
	HNL          // Lempira (340)
	HRD          // Deprecated: Croatian Dinar (191)
	HRK          // Deprecated: Kuna (191)
	HTG          // Gourde (332)
	HUF          // Forint (348)
	IDR          // Rupiah (360)
	IEP          // Deprecated: Irish Pound (372)
	ILP          // Deprecated: Pound (376)
	ILR          // Deprecated: Old Shekel (376)
	ILS          // New Israeli Sheqel (376)
	INR          // Indian Rupee (356)
	IQD          // Iraqi Dinar (368)
	IRR          // Iranian Rial (364)
	ISJ          // Deprecated: Old Krona (352)
	ISK          // Iceland Krona (352)
	ITL          // Deprecated: Italian Lira (380)
	JMD          // Jamaican Dollar (388)
	JOD          // Jordanian Dinar (400)
	JPY          // Yen (392)
	KES          // Kenyan Shilling (404)
	KGS          // Som (417)
	KHR          // Riel (116)
	KMF          // Comorian Franc  (174)
	KPW          // North Korean Won (408)
	KRW          // Won (410)
	KWD          // Kuwaiti Dinar (414)
	KYD          // Cayman Islands Dollar (136)
	KZT          // Tenge (398)
	LAJ          // Deprecated: Pathet Lao Kip (418)
	LAK          // Lao Kip (418)
	LBP          // Lebanese Pound (422)
	LKR          // Sri Lanka Rupee (144)
	LRD          // Liberian Dollar (430)
	LSL          // Loti (426)
	LSM          // Deprecated: Loti (426)
	LTL          // Deprecated: Lithuanian Litas (440)
	LTT          // Deprecated: Talonas (440)
	LUC          // Deprecated: Luxembourg Convertible Franc (989)
	LUF          // Deprecated: Luxembourg Franc (442)
	LUL          // Deprecated: Luxembourg Financial Franc (988)
	LVL          // Deprecated: Latvian Lats (428)
	LVR          // Deprecated: Latvian Ruble (428)
	LYD          // Libyan Dinar (434)
	MAD          // Moroccan Dirham (504)
	MDL          // Moldovan Leu (498)
	MGA          // Malagasy Ariary (969)
	MGF          // Deprecated: Malagasy Franc (450)
	MKD          // Denar (807)
	MLF          // Deprecated: Mali Franc (466)
	MMK          // Kyat (104)
	MNT          // Tugrik (496)
	MOP          // Pataca (446)
	MRO          // Deprecated: Ouguiya (478)
	MRU          // Ouguiya (929)
	MTL          // Deprecated: Maltese Lira (470)
	MTP          // Deprecated: Maltese Pound (470)
	MUR          // Mauritius Rupee (480)
	MVQ          // Deprecated: Maldive Rupee (462)
	MVR          // Rufiyaa (462)
	MWK          // Malawi Kwacha (454)
	MXN          // Mexican Peso (484)
	MXP          // Deprecated: Mexican Peso (484)
	MXV          // Mexican Unidad de Inversion (UDI) (979)
	MYR          // Malaysian Ringgit (458)
	MZE          // Deprecated: Mozambique Escudo (508)
	MZM          // Deprecated: Mozambique Metical (508)
	MZN          // Mozambique Metical (943)
	NAD          // Namibia Dollar (516)
	NGN          // Naira (566)
	NIC          // Deprecated: Cordoba (558)
	NIO          // Cordoba Oro (558)
	NLG          // Deprecated: Netherlands Guilder (528)
	NOK          // Norwegian Krone (578)
	NPR          // Nepalese Rupee (524)
	NZD          // New Zealand Dollar (554)
	OMR          // Rial Omani (512)
	PAB          // Balboa (590)
	PEH          // Deprecated: Sol (604)
	PEI          // Deprecated: Inti (604)
	PEN          // Sol (604)
	PES          // Deprecated: Sol (604)
	PGK          // Kina (598)
	PHP          // Philippine Peso (608)
	PKR          // Pakistan Rupee (586)
	PLN          // Zloty (985)
	PLZ          // Deprecated: Zloty (616)
	PTE          // Deprecated: Portuguese Escudo (620)
	PYG          // Guarani (600)
	QAR          // Qatari Rial (634)
	RHD          // Deprecated: Rhodesian Dollar (716)
	ROK          // Deprecated: Leu A/52 (642)
	ROL          // Deprecated: Old Leu (642)
	RON          // Romanian Leu (946)
	RSD          // Serbian Dinar (941)
	RUB          // Russian Ruble (643)
	RUR          // Deprecated: Russian Ruble (810)
	RWF          // Rwanda Franc (646)
	SAR          // Saudi Riyal (682)
	SBD          // Solomon Islands Dollar (090)
	SCR          // Seychelles Rupee (690)
	SDD          // Deprecated: Sudanese Dinar (736)
	SDG          // Sudanese Pound (938)
	SDP          // Deprecated: Sudanese Pound (736)
	SEK          // Swedish Krona (752)
	SGD          // Singapore Dollar (702)
	SHP          // Saint Helena Pound (654)
	SIT          // Deprecated: Tolar (705)
	SKK          // Deprecated: Slovak Koruna (703)
	SLE          // Leone (925)
	SLL          // Leone (694)
	SOS          // Somali Shilling (706)
	SRD          // Surinam Dollar (968)
	SRG          // Deprecated: Surinam Guilder (740)
	SSP          // South Sudanese Pound (728)
	STD          // Deprecated: Dobra (678)
	STN          // Dobra (930)
	SUR          // Deprecated: Rouble (810)
	SVC          // El Salvador Colon (222)
	SYP          // Syrian Pound (760)
	SZL          // Lilangeni (748)
	THB          // Baht (764)
	TJR          // Deprecated: Tajik Ruble (762)
	TJS          // Somoni (972)
	TMM          // Deprecated: Turkmenistan Manat (795)
	TMT          // Turkmenistan New Manat (934)
	TND          // Tunisian Dinar (788)
	TOP          // Pa’anga (776)
	TPE          // Deprecated: Timor Escudo (626)
	TRL          // Deprecated: Old Turkish Lira (792)
	TRY          // Turkish Lira (949)
	TTD          // Trinidad and Tobago Dollar (780)
	TWD          // New Taiwan Dollar (901)
	TZS          // Tanzanian Shilling (834)
	UAH          // Hryvnia (980)
	UAK          // Deprecated: Karbovanet (804)
	UGS          // Deprecated: Uganda Shilling (800)
	UGW          // Deprecated: Old Shilling (800)
	UGX          // Uganda Shilling (800)
	USD          // US Dollar (840)
	USN          // US Dollar (Next day) (997)
	USS          // Deprecated: US Dollar (Same day) (998)
	UYI          // Uruguay Peso en Unidades Indexadas (UI) (940)
	UYN          // Deprecated: Old Uruguay Peso (858)
	UYP          // Deprecated: Uruguayan Peso (858)
	UYU          // Peso Uruguayo (858)
	UYW          // Unidad Previsional (927)
	UZS          // Uzbekistan Sum (860)
	VEB          // Deprecated: Bolivar (862)
	VED          // Bolívar Soberano (926)
	VEF          // Deprecated: Bolívar (937)
	VES          // Bolívar Soberano (928)
	VNC          // Deprecated: Old Dong (704)
	VND          // Dong (704)
	VUV          // Vatu (548)
	WST          // Tala (882)
	XAF          // CFA Franc BEAC (950)
	XAG          // Silver (961)
	XAU          // Gold (959)
	XBA          // Bond Markets Unit European Composite Unit (EURCO) (955)
	XBB          // Bond Markets Unit European Monetary Unit (E.M.U.-6) (956)
	XBC          // Bond Markets Unit European Unit of Account 9 (E.U.A.-9) (957)
	XBD          // Bond Markets Unit European Unit of Account 17 (E.U.A.-17) (958)
	XCD          // East Caribbean Dollar (951)
	XDR          // SDR (Special Drawing Right) (960)
	XEU          // Deprecated: European Currency Unit (E.C.U) (954)
	XFO          // Deprecated: Gold-Franc ()
	XFU          // Deprecated: UIC-Franc ()
	XOF          // CFA Franc BCEAO (952)
	XPD          // Palladium (964)
	XPF          // CFP Franc (953)
	XPT          // Platinum (962)
	XRE          // Deprecated: RINET Funds Code ()
	XSU          // Sucre (994)
	XTS          // Codes specifically reserved for testing purposes (963)
	XUA          // ADB Unit of Account (965)
	XXX          // The codes assigned for transactions where no currency is involved (999)
	YDD          // Deprecated: Yemeni Dinar (720)
	YER          // Yemeni Rial (886)
	YUD          // Deprecated: New Yugoslavian Dinar (890)
	YUM          // Deprecated: New Dinar (891)
	YUN          // Deprecated: Yugoslavian Dinar (890)
	ZAL          // Deprecated: Financial Rand (991)
	ZAR          // Rand (710)
	ZMK          // Deprecated: Zambian Kwacha (894)
	ZMW          // Zambian Kwacha (967)
	ZRN          // Deprecated: New Zaire (180)
	ZRZ          // Deprecated: Zaire (180)
	ZWC          // Deprecated: Rhodesian Dollar (716)
	ZWD          // Deprecated: Zimbabwe Dollar (716)
	ZWL          // Zimbabwe Dollar (932)
	ZWN          // Deprecated: Zimbabwe Dollar (new) (942)
	ZWR          // Deprecated: Zimbabwe Dollar (935)
)

func FromAlpha

func FromAlpha(alpha string) (Currency, error)

FromAlpha returns Currency for the three-letter alpha code. Or an error if it does not exist.

Example
package main

import (
	"fmt"

	"github.com/ferdypruis/iso4217"
)

func main() {
	currency, _ := iso4217.FromAlpha("EUR") // Ignoring error for simplicity
	fmt.Println("The three-digit numeric code for the", currency.Name(), "is", currency.Numeric())

}
Output:

The three-digit numeric code for the Euro is 978

func FromNumeric

func FromNumeric(numeric string) (Currency, error)

FromNumeric returns Currency for the three-digit numeric code. Or an error if it does not exist.

Example
package main

import (
	"fmt"

	"github.com/ferdypruis/iso4217"
)

func main() {
	currency, _ := iso4217.FromNumeric("608") // Ignoring error for simplicity
	fmt.Println(currency.Alpha(), "is the alphabetic currency code for the", currency.Name())

}
Output:

PHP is the alphabetic currency code for the Philippine Peso

func Must

func Must(c Currency, err error) Currency

Must panics if err is non-nil and otherwise returns c. Could be used to return a single value from FromAlpha/FromNumeric.

Example
package main

import (
	"fmt"

	"github.com/ferdypruis/iso4217"
)

func main() {
	fmt.Println("The numeric code for euros is", iso4217.Must(iso4217.FromAlpha("EUR")).Numeric())

}
Output:

The numeric code for euros is 978

func (Currency) Alpha

func (c Currency) Alpha() string

Alpha returns the ISO 4217 three-letter alphabetic code.

func (Currency) Exponent

func (c Currency) Exponent() int

Exponent returns the decimal point location.

Example
package main

import (
	"fmt"

	"github.com/ferdypruis/iso4217"
)

func main() {
	rates := []struct {
		currency iso4217.Currency
		amount   float32
	}{
		{iso4217.CAD, 1.30488},
		{iso4217.JPY, 110.10},
		{iso4217.CLF, 0.028043},
	}

	fmt.Println("Today, one United States Dollar equals;")
	for _, r := range rates {
		fmt.Printf("- %.*f %s\n", r.currency.Exponent(), r.amount, r.currency.Name())
	}

}
Output:

Today, one United States Dollar equals;
- 1.30 Canadian Dollar
- 110 Yen
- 0.0280 Unidad de Fomento

func (Currency) Name

func (c Currency) Name() string

Name returns the English name.

func (Currency) Numeric

func (c Currency) Numeric() string

Numeric returns the ISO 4217 three-digit numeric code.

type Error

type Error string

Error is the type of error returned by this package

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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