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

JanGalek actions-user