gopher-money

command module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: MIT Imports: 9 Imported by: 0

README

Test GoDoc

gopher-money

Command line utility for all things money

gopher-money convert USD JPY 44.3
> 4679.36746875
gopher-money round JPY 44.3
> 44
gopher-money format USD 44.3
> $44.30

Install using the following command

go get github.com/aaron-hardin/gopher-money

gopher-money - rates GoDoc

Wrapper around Open Exchange Rates to provide a convenient way to get current exchange rates

client := rates.NewApiClient(apiKey)
// rates is map[string]float64
// mapping currency code to current exchange rate
rates, err := client.GetRates()

gopher-money - money GoDoc

Provides functionality for using rates to convert between currencies

converter := money.NewConverter(rates)
rawValue, err := converter.Convert(fromCurrencyCode, toCurrencyCode, value)

gopher-money - format GoDoc

Provides functionality for formatting currencies, allows converting to correct precision as well as formatting to string with symbol

When providing a custom format string, %v is used for the value and %s is used for the currency symbol

roundedValue, err := format.Round(currencyCode, value)
displayValue, err := format.Format(currencyCode, value)
displayValue, err = format.FormatAs(currencyCode, value, customFormat)

TODO

  • Add more features to rates library to support more features of Open Exchange Rates

Documentation

Overview

gopher-money is a tool for all things money.

Usage:

gopher-money <command> [arguments]

The commands are:

convert     convert from one currency to another
round       round currency to nearest whole amount
format      format a currency amount

Use "gopher-money <command> --help" for more information about a command.

Convert from one currency to another

Usage:

gopher-money convert <from currency code> <to currency code> <value to convert> [--apiKey=<apiKey>] [--cache]

Convert uses current exchange rates to convert from one currency to another.

The apiKey is optional and defaults to the environment variable GOPHER_MONEY_API_KEY

If cache is specified then a local file gopher-money-rates-cache.txt will be used for caching exchange rates.

Round currency to nearest whole amount

Usage:

gopher-money round <currency> <value>

Round takes an input value and rounds to the nearest whole unit according to the currency code.

Examples:

USD
  The standard unit for US dollar is 1 cent so it will be rounded to nearest .01
JPY
  The standard unit for Japanese Yen is 1 yen so it will be rounded to the nearest 1

Format a currency amount

Usage:

gopher-money format <currency> <value> [format]

Format takes an input value and formats it according to the currency code. The value is first rounded in the way that the round command is applied. The result is then formatted according to the format string with a default of %s%v. %v specifies the value after rounding %s specifies the currency symbol

Directories

Path Synopsis
Package format is used to format currencies.
Package format is used to format currencies.
Package money provides support for converting between currencies.
Package money provides support for converting between currencies.
Package rates provides support for getting exchange rates from Open Exchange Rates.
Package rates provides support for getting exchange rates from Open Exchange Rates.

Jump to

Keyboard shortcuts

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