currency

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: Apache-2.0 Imports: 4 Imported by: 7

README

Currency Reference Data

Data sourced from ISO website and providers.

ISO 4217

Currency code data sourced from: https://www.iso.org/iso-4217-currency-codes.html

Documentation

Overview

Package currency provides models for dealing with currencies.

Index

Constants

This section is empty.

Variables

View Source
var CodeDefinitions = []Def{}/* 166 elements not displayed */

CodeDefinitions lists all the currencies we know about with extra data.

Functions

This section is empty.

Types

type Code

type Code string

Code is the ISO currency code

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

List of ISO4217 currency codes.

const CodeEmpty Code = ""

CodeEmpty is used when there is no code.

func (Code) Def added in v0.29.0

func (c Code) Def() Def

Def provides the currency definition for the code.

func (Code) JSONSchema added in v0.29.0

func (Code) JSONSchema() *jsonschema.Schema

JSONSchema provides a representation of the struct for usage in Schema.

func (Code) Validate

func (c Code) Validate() error

Validate ensures the currency code is valid according to the ISO 4217 three-letter list.

type Def

type Def struct {
	Code  Code   `json:"code"`  // three-letter currency code
	Name  string `json:"name"`  // name of the currency
	Num   string `json:"num"`   // three-digit currency code
	Units uint32 `json:"units"` // how many cents are used for the currency
}

Def provides a structure for the currencies

func Get

func Get(c Code) (Def, bool)

Get provides the code's currency definition, or false if none is found.

func (Def) BaseAmount deprecated

func (d Def) BaseAmount() num.Amount

BaseAmount provides a definition's zero amount with the correct decimal places so that it can be used as a base for calculating totals.

Deprecated: please now use the Zero method instead.

func (Def) Zero added in v0.52.2

func (d Def) Zero() num.Amount

Zero provides the currency's zero amount which is pre-set with the minimum precision for the currency.

type ExchangeRate

type ExchangeRate struct {
	// ISO currency code this rate represents.
	Currency Code `json:"currency" jsonschema:"title=Currency"`
	// How much is 1.00 of this currency worth in the documents currency.
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
}

ExchangeRate contains data on the rate to be used when converting amounts from the document's base currency to whatever is defined.

It should be possible to take any amount in the matching currency and multiply it by the amount defined in the exchange rate to determine the value.

For example, our document is in EUR and some amounts are defined in USD. Our ExchangeRate instance may be defined and used as:

  rate := &currency.ExchangeRate{
	   Currency: currency.USD,
    Amount: "0.875967",
  }

  val := "100.00" // USD
  val.Multiply(rate.Amount) // EUR: "87.60"

Jump to

Keyboard shortcuts

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