currency

package module
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: MIT Imports: 4 Imported by: 0

README

Currency

godoc

A golang library to deal with money and currency representation.

Installation

$ go get github.com/Hunrik/currency

Usage

First, import the package adding:

import "github.com/Hunrik/currency"

Examples:

currency.Format(10, "USD")                                  // "$10.00"
currency.Format(10, "EUR")                                  // "€10.00"
currency.Format(10, "USD", WithCents(false))                // "$10"
currency.Format(10, "USD", WithCurrency(true))              // "$10.00 USD"
currency.Format(10, "USD", WithSymbol(false)                // "10.00"
currency.Format(10, "USD", WithSymbolSpace(true)            // "$ 10.00"
currency.Format(1000, "USD")                                // "$1,000.00"
currency.Format(1000, "USD", WithThousandsSeparator(false)  // "$1000.00"

For more detailed documentation refer to godoc

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The MIT licence

Documentation

Overview

package currency is a library to deal with money and currency representation.

Usage

Format(10, "USD")                                   // "$10.00"
Format(10, "EUR")                   								// "€10.00"
Format(10, "USD", WithCents(false))                 // "$10"
Format(10, "USD", WithCurrency(true))              	// "$10.00 USD"
Format(10, "USD", WithSymbol(false)                	// "10.00"
Format(10, "USD", WithSymbolSpace(true)            	// "$ 10.00"
Format(1000, "USD")                                 // "$1,000.00"
Format(1000, "USD", WithThousandsSeparator(false)	  // "$1000.00"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(amount float64, currency string, opts ...OptionsFn) string

Format returns a formatted price string according to currency rules and options

Types

type Options

type Options struct {
	WithCents              bool
	WithCurrency           bool
	WithSymbol             bool
	WithSymbolSpace        bool
	WithThousandsSeparator bool
}
Options {
	WithCents:              true,
	WithCurrency:           false,
	WithSymbol:             true,
	WithSymbolSpace:        false,
	WithThousandsSeparator: true,
}

type OptionsFn

type OptionsFn func(*Options)

OptionsFn function parameter

func WithCents

func WithCents(val bool) OptionsFn

WithCents Should display cents or not Default true

func WithCurrency

func WithCurrency(val bool) OptionsFn

WithCurrency Should add currency text or not Default false

func WithSymbol

func WithSymbol(val bool) OptionsFn

WithSymbol Should display symbol or not Default true

func WithSymbolSpace

func WithSymbolSpace(val bool) OptionsFn

WithSymbolSpace Should add space between symbol or not Default false

func WithThousandsSeparator

func WithThousandsSeparator(val bool) OptionsFn

WithThousandsSeparator Should use thousand separator or not Default true

Jump to

Keyboard shortcuts

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