currency

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: BSD-3-Clause Imports: 3 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Currency

The currency package provides functionality to manage and validate different currency codes and their details. It contains a list of currency codes with information such as the name, symbol, and minor units (decimal places). You can use this package to retrieve currency information and validate whether a currency code exists. (ISO 4217)

GoDoc GitHub stars Go Report Card codecov

Versions

Stable Version GitHub Release GitHub Release

Features

  • Search for a currency by its code (e.g., USD, EUR).
  • Validate if a currency code exists.
  • Return detailed information such as currency name, symbol, and minor units.

Installation

go get -u github.com/gouef/currency

Usages

Finding a currency

You can use the FindCurrency function to search for a currency by its code. It returns a pointer to the Currency struct, which contains details like the name, symbol, and minor units.

package main

import (
	"fmt"
	"log"
	"github.com/gouef/currency"
)

func main() {
	code := "USD"
	curr, err := currency.FindCurrency(code)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	fmt.Printf("Currency Code: %s\n", curr.Code)
	fmt.Printf("Currency Name: %s\n", curr.Name)
	fmt.Printf("Currency Symbol: %s\n", curr.Symbol)
	fmt.Printf("Minor Units: %d\n", curr.MinorUnits)
}

Validating a Currency Code

To check whether a currency code is valid, use the ValidateCurrency function. It returns true if the code exists and false otherwise.

package main

import (
	"fmt"
	"log"
	"github.com/gouef/currency"
)

func main() {
	code := "EUR"
	if currency.ValidateCurrency(code) {
		fmt.Printf("The currency code %s is valid!\n", code)
	} else {
		log.Printf("The currency code %s is not valid.\n", code)
	}
}

Contributing

Read Contributing

Contributors

actions-user JanGalek VolkerLieber

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List added in v1.0.4

func List() map[string]Currency

List return list of all currencies

func UniqueSymbolList added in v1.0.4

func UniqueSymbolList() map[string]Currency

UniqueSymbolList return list of unique currencies symbols

func ValidateCurrency

func ValidateCurrency(code string) bool

ValidateCurrency validate currency code

valid := ValidateCurrency("USD")

Types

type Currency

type Currency struct {
	Code       string `json:"code"`
	Name       string `json:"name"`
	Symbol     string `json:"symbol"`
	MinorUnits int    `json:"minor_units"`
}

func FindCurrenciesBySymbol added in v1.0.4

func FindCurrenciesBySymbol(symbol string) []Currency

FindCurrenciesBySymbol return list of Currency by symbol

currencies := FindCurrenciesBySymbol("€")

func FindCurrency

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

FindCurrency search of all currency codes and returns Currency struct

curr := FindCurrency("USD")

func FindUniqueSymbolCurrency added in v1.0.3

func FindUniqueSymbolCurrency(symbol string) (*Currency, error)

FindUniqueSymbolCurrency returns the Currency struct for the provided currency symbol, if it is unique for that currency

curr := FindUniqueSymbolCurrency("€")

func (*Currency) HasUniqueSymbol added in v1.0.4

func (currency *Currency) HasUniqueSymbol() bool

HasUniqueSymbol check if Currency has unique symbol

isUnique := currency.HasUniqueSymbol()

Jump to

Keyboard shortcuts

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