money and currency formatting for golang

Related tags

Financial accounting
Overview

accounting - money and currency formatting for golang

Build Status Coverage Status GoDoc

accounting is a library for money and currency formatting. (inspired by accounting.js)

Quick Start

go get github.com/leekchan/accounting

example.go

package main

import (
    "fmt"
    "math/big"

    "github.com/shopspring/decimal"
    "github.com/leekchan/accounting"
)

func main() {
    ac := accounting.Accounting{Symbol: "$", Precision: 2}
    fmt.Println(ac.FormatMoney(123456789.213123))                       // "$123,456,789.21"
    fmt.Println(ac.FormatMoney(12345678))                               // "$12,345,678.00"
    fmt.Println(ac.FormatMoney(big.NewRat(77777777, 3)))                // "$25,925,925.67"
    fmt.Println(ac.FormatMoney(big.NewRat(-77777777, 3)))               // "-$25,925,925.67"
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(123456789.213123))) // "$123,456,789.21"
    fmt.Println(ac.FormatMoneyDecimal(decimal.New(123456789.213123, 0))) // "$123,456,789.21"

    ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
    fmt.Println(ac.FormatMoney(4999.99))  // "€4.999,99"

    // Or retrieve currency info from Locale struct
    lc := LocaleInfo["USD"]
    ac = accounting.Accounting{Symbol: lc.ComSymbol, Precision: 2, Thousand: lc.ThouSep, Decimal: lc.DecSep}
    fmt.Println(ac.FormatMoney(500000)) // "$500,000.00"

    ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
    fmt.Println(ac.FormatMoney(500000)) // "£ 500,000"

    ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
        Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
    fmt.Println(ac.FormatMoney(1000000)) // "GBP 1,000,000"
    fmt.Println(ac.FormatMoney(-5000))   // "GBP (5,000)"
    fmt.Println(ac.FormatMoney(0))       // "GBP --"

    ac = accounting.DefaultAccounting("GBP", 2)
    fmt.Println(ac.FormatMoney(1000000)) // "GBP 1,000,000"
    fmt.Println(ac.FormatMoney(-5000))   // "GBP (5,000)"
    fmt.Println(ac.FormatMoney(0))       // "GBP --"

    ac = accounting.NewAccounting("GBP", 2, ",", ".", "%s %v", "%s (%v)", "%s --")
    fmt.Println(ac.FormatMoney(1000000)) // "GBP 1,000,000"
    fmt.Println(ac.FormatMoney(-5000))   // "GBP (5,000)"
    fmt.Println(ac.FormatMoney(0))       // "GBP --"
}

Caution

Please do not use float64 to count money. Floats can have errors when you perform operations on them. Using big.Rat (< Go 1.5) or big.Float (>= Go 1.5) is highly recommended. (accounting supports float64, but it is just for convenience.)

Initialization

Accounting struct

type Accounting struct {
    Symbol         string // currency symbol (required)
    Precision      int    // currency precision (decimal places) (optional / default: 0)
    Thousand       string // thousand separator (optional / default: ,)
    Decimal        string // decimal separator (optional / default: .)
    Format         string // simple format string allows control of symbol position (%v = value, %s = symbol) (default: %s%v)
    FormatNegative string // format string for negative values (optional / default: strings.Replace(strings.Replace(accounting.Format, "-", "", -1), "%v", "-%v", -1))
    FormatZero     string // format string for zero values (optional / default: Format)
}
Field Type Description Default Example
Symbol string currency symbol no default value $
Precision int currency precision (decimal places) 0 2
Thousand string thousand separator , .
Decimal string decimal separator . ,
Format string simple format string allows control of symbol position (%v = value, %s = symbol) %s%v %s %v
FormatNegative string format string for negative values strings.Replace(strings.Replace(accounting.Format, "-", "", -1), "%v", "-%v", -1)) %s (%v)
FormatZero string format string for zero values Format %s --

Examples:

# Via functions
ac := accounting.DefaultAccounting("$", 2)
ac := accounting.NewAccounting("$", 2, ",", ".", "%s %v", "%s (%v)", "%s --")

# Via Accounting struct
ac := accounting.Accounting{Symbol: "$", Precision: 2}

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
        Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}

SetThousandSeparator(str string)

SetThousandSeparator sets the separator for the thousands separation

SetDecimalSeparator(str string)

SetDecimalSeparator sets the separator for the decimal separation

SetFormat(str string)

SetFormat sets the Format default: %s%v (%s=Symbol;%v=Value)

SetFormatNegative(str string)

SetFormatNegative sets the Format for negative values default: -%s%v (%s=Symbol;%v=Value)

SetFormatZero(str string)

SetFormatZero sets the Format for zero values default: %s%v (%s=Symbol;%v=Value)

Locale struct

type Locale struct {
    Name           string // currency name
    FractionLength int    // default decimal length
    ThouSep        string // thousands seperator
    DecSep         string // decimal seperator
    SpaceSep       string // space seperator
    UTFSymbol      string // UTF symbol
    HTMLSymbol     string // HTML symbol
    ComSymbol      string // Common symbol
    Pre            bool   // symbol before or after currency
}
Field Type Description Default Example
Name string currency name no default value US Dollar
FractionLength int default precision (decimal places) no default value 2
ThouSep string thousand separator no default value ,
DecSep string decimal separator no default value .
SpaceSep string space separator no default value " "
UTFSymbol string UTF symbol no default value "0024"
HTMLSymbol string HTML symbol no default value "&#x0024"
ComSymbol string Common symbol no default value "$"
Pre bool symbol before currency no default value true

Example:

// LocaleInfo map[string]Locale

var lc Locale
if val, ok := LocaleInfo["USD"]; ok {
    lc = val
} else {
    panic("No Locale Info Found")
}

fmt.Println(lc.Name) // "US Dollar"
fmt.Println(lc.FractionLength) // 2
fmt.Println(lc.ThouSep) // ","
fmt.Println(lc.DecSep) // "."
fmt.Println(lc.SpaceSep) // ""
fmt.Println(lc.UTFSymbol) // "0024"
fmt.Println(lc.HTMLSymbol) // "&#x0024"
fmt.Println(lc.ComSymbol) // "$"
fmt.Println(lc.Pre) // true

There are currently 181 currencies supported in LocaleInfo

FormatMoney(value interface{}) string

FormatMoney is a function for formatting numbers as money values, with customisable currency symbol, precision (decimal places), and thousand/decimal separators.

FormatMoney supports various types of value by runtime reflection. If you don't need runtime type evaluation, please refer to FormatMoneyInt, FormatMoneyBigRat, FormatMoneyBigRat, or FormatMoneyFloat64.

  • supported value types : int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, *big.Rat

Examples:

ac := accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoney(123456789.213123))         // "$123,456,789.21"
fmt.Println(ac.FormatMoney(12345678))                 // "$12,345,678.00"
fmt.Println(ac.FormatMoney(big.NewRat(77777777, 3)))  // "$25,925,925.67"
fmt.Println(ac.FormatMoney(big.NewRat(-77777777, 3))) // "-$25,925,925.67"

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
fmt.Println(ac.FormatMoney(4999.99))  // "€4.999,99"

ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
fmt.Println(ac.FormatMoney(500000)) // "£ 500,000"

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
    Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
fmt.Println(ac.FormatMoney(1000000)) // "GBP 1,000,000"
fmt.Println(ac.FormatMoney(-5000))   // "GBP (5,000)"
fmt.Println(ac.FormatMoney(0))       // "GBP --"

FormatMoneyBigFloat(value *big.Float) string

(>= Go 1.5)

FormatMoneyBigFloat only supports *big.Float value. It is faster than FormatMoney, because it does not do any runtime type evaluation.

Examples:

ac = accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(123456789.213123))) // "$123,456,789.21"
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(12345678)))         // "$12,345,678.00"

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(4999.99)))  // "€4.999,99"

ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(500000))) // "£ 500,000"

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
    Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(1000000))) // "GBP 1,000,000"
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(-5000)))   // "GBP (5,000)"
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(0)))       // "GBP --"

FormatMoneyInt(value int) string

FormatMoneyInt only supports int value. It is faster than FormatMoney, because it does not do any runtime type evaluation.

Examples:

ac = accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoneyInt(12345678)) // "$12,345,678.00"

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
fmt.Println(ac.FormatMoneyInt(4999))  // "€4.999,00"

ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
fmt.Println(ac.FormatMoneyInt(500000)) // "£ 500,000"

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
    Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
fmt.Println(ac.FormatMoneyInt(1000000)) // "GBP 1,000,000"
fmt.Println(ac.FormatMoneyInt(-5000))   // "GBP (5,000)"
fmt.Println(ac.FormatMoneyInt(0))       // "GBP --"

FormatMoneyBigRat(value *big.Rat) string

FormatMoneyBigRat only supports *big.Rat value. It is faster than FormatMoney, because it does not do any runtime type evaluation.

Examples:

ac = accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(77777777, 3)))  // "$25,925,925.67"
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(-77777777, 3))) // "-$25,925,925.67"

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(77777777, 3)))  // "€25.925.925,67"

ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(77777777, 3)))  // "£ 25,925,926"

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
    Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(77777777, 3)))  // "GBP 25,925,926"
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(-77777777, 3))) // "GBP (25,925,926)"
fmt.Println(ac.FormatMoneyBigRat(big.NewRat(0, 3)))         // "GBP --"

FormatMoneyFloat64(value float64) string

FormatMoneyFloat64 only supports float64 value. It is faster than FormatMoney, because it does not do any runtime type evaluation.

Examples:

ac = accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoneyFloat64(123456789.213123)) // "$123,456,789.21"
fmt.Println(ac.FormatMoneyFloat64(12345678))         // "$12,345,678.00"

ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
fmt.Println(ac.FormatMoneyFloat64(4999.99))  // "€4.999,99"

ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
fmt.Println(ac.FormatMoneyFloat64(500000)) // "£ 500,000"

ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
    Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
fmt.Println(ac.FormatMoneyFloat64(1000000)) // "GBP 1,000,000"
fmt.Println(ac.FormatMoneyFloat64(-5000))   // "GBP (5,000)"
fmt.Println(ac.FormatMoneyFloat64(0))       // "GBP --"

FormatNumber(value interface{}, precision int, thousand string, decimal string) string

FormatNumber is a base function of the library which formats a number with custom precision and separators.

FormatNumber supports various types of value by runtime reflection. If you don't need runtime type evaluation, please refer to FormatNumberInt, FormatNumberBigRat, or FormatNumberFloat64.

  • supported value types : int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, *big.Rat

Examples:

fmt.Println(accounting.FormatNumber(123456789.213123, 3, ",", ".")) // "123,456,789.213"
fmt.Println(accounting.FormatNumber(1000000, 3, " ", ","))          // "1 000 000,000"

FormatNumberBigFloat(value *big.Float, precision int, thousand string, decimal string) string

(>= Go 1.5)

FormatNumberBigFloat only supports *big.Float value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

fmt.Println(accounting.FormatNumberBigFloat(big.NewFloat(123456789.213123), 3, ",", ".")) // "123,456,789.213"

FormatNumberInt(value int, precision int, thousand string, decimal string) string

FormatNumberInt only supports int value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

fmt.Println(accounting.FormatNumberInt(123456789, 3, ",", ".")) // "123,456,789.000"

FormatNumberBigRat(value *big.Rat, precision int, thousand string, decimal string) string

FormatNumberBigRat only supports *big.Rat value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

fmt.Println(accounting.FormatNumberBigRat(big.NewRat(77777777, 3), 3, ",", ".")) // "25,925,925.667"

FormatNumberFloat64(value float64, precision int, thousand string, decimal string) string

FormatNumberFloat64 only supports float64 value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

fmt.Println(accounting.FormatNumberFloat64(123456789.213123, 3, ",", ".")) // "123,456,789.213"

FormatNumberDecimal(value decimal.Decimal, precision int, thousand string, decimal string) string

FormatNumberDecimal only supports decimal.Decimal value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

import "github.com/shopspring/decimal"
fmt.Println(accounting.FormatNumberBigDecimal(apd.New(apd.New(4999999, -3), 3, ",", ".")) // "4,999.999"

FormatNumberBigDecimal(value apd.Decimal, precision int, thousand string, decimal string) string

FormatNumberDecimal only supports apd.Decimal value. It is faster than FormatNumber, because it does not do any runtime type evaluation.

Examples:

import "github.com/cockroachdb/apd"
fmt.Println(accounting.FormatNumberDecimal(decimal.New(123456789.213123,3), 3, ",", ".")) // "123,456,789.213"

UnformatNumber(number string, precision int, currency string) string

UnformatNumber is the inverse of FormatNumber. It strips out all currency formatting and returns the number with a point for the decimal seperator.

Examples:

fmt.Println(accounting.UnformatNumber("$45,000.50", 2, "USD")) // "45000.50"
fmt.Println(accounting.UnformatNumber("EUR 12.500,3474", 3, "EUR")) // "12500.347"
Issues
  • Blocking Urgent Problem

    Blocking Urgent Problem

    Hi.

    It seems the package github.com/cockroachdb/apd was update yesterday and I am getting this.

    github.com/leekchan/accounting
    ../../leekchan/accounting/formatnumber.go:79: d.ToStandard undefined (type *apd.Decimal has no field or method ToStandard)
    ../../leekchan/accounting/formatnumber.go:139: d.ToStandard undefined (type *apd.Decimal has no field or method ToStandard)
    

    @leekchan Can you fix the problem?

    opened by cristian-sima 4
  • Proposal: Please start using Semantic Versioning

    Proposal: Please start using Semantic Versioning

    I found that this project already supports Go modules. But sadly, the tags doesn't follow Semantic Versioning, which means that all tags of this project will be ignored by Go modules and replaced by pseudo-versions, go get acts weirdly when tags are not in that form. It would be great to have the tagged release be named in the format vX.X.X format so that go mod can read it.

    $ go get github.com/leekchan/[email protected]
    go get github.com/leekchan/[email protected]: no matching versions for query "v0.3"
    $ go get github.com/leekchan/accounting
    go: downloading github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4
    go: github.com/leekchan/accounting upgrade => v0.0.0-20191218023648-17a4ce5f94d4
    github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4
    

    Else the mod file shows something like github.com/leekchan/accounting v0.0.0-20191218023648-17a4ce5f94d4 which is not very readable and difficult to upgrade. It’s hard to verify which version is in use. This is not conducive to version control

    So, I propose this project to follow Semantic Versioning in future versions. For example, v1.0.1, v2.0.0, v3.1.0-alpha, v3.1.0-beta.2etc.

    opened by KateGo520 3
  • Use formattedNumber to format zero

    Use formattedNumber to format zero

    If precision is a , then the old code would compare 0.00 with 0,00 and FormatZero wouldn't be used.

    So format the value 0 with FormatNumber and it will work :)

    opened by bykof 3
  • Locale Info and UnformatNumber

    Locale Info and UnformatNumber

    I wanted to expand on this and make it easier to get information on different currencies with just the ISO. I added a locale.go file that is a map of Locale structs that contain info on a currency based on the ISO code.
    I also added an unformat number method that takes any formatted currency value and returns a string value of the number with all the currency formatting removed and a decimal inserted at the specified precision.

    opened by djackreuter 2
  • Change symbol on Indonesia Rupiah

    Change symbol on Indonesia Rupiah

    Based on https://badanbahasa.kemdikbud.go.id/lamanbahasa/sites/default/files/PUEBI.pdf Indonesia Rupiah is using Rp symbol without any "." or space, so I remove the "." after the Rp

    opened by agungcandra 1
  • Cannot compile for 32-bit

    Cannot compile for 32-bit

    Error: leekchan/accounting/formatnumber.go:90: constant -9223372036854775808 overflows int

    Won't compile for 32-bit architectures (main target is ARMv7)

    opened by superlinkx 1
  • constant -9223372036854775808 overflows int

    constant -9223372036854775808 overflows int

    I'm getting this error when trying to build (go 1.6 - GOOS=linux GOARCH=386 go build):

    github.com/leekchan/accounting
    ../../../.gvm/pkgsets/go1.6/global/src/github.com/leekchan/accounting/formatnumber.go:90: constant -9223372036854775808 overflows int
    

    Any advice?

    Thanks.

    opened by rvillas 1
  • Error github.com/leekchan/accounting@v1.0.0: reading github.com/leekchan/accounting/go.mod at revision v1.0.0: unknown revision v1.0.0

    Error github.com/leekchan/[email protected]: reading github.com/leekchan/accounting/go.mod at revision v1.0.0: unknown revision v1.0.0

    When I try to execute the command

      "go get github.com/leekchan/accounting" 
    

    I receive the error

      "go: github.com/leekchan/[email protected]: reading github.com/leekchan/accounting/go.mod at revision v1.0.0: unknown revision v1.0.0"
    
    opened by Mgescud 2
  • Some features in Locale aren't available for formatting

    Some features in Locale aren't available for formatting

    Hi, thanks for a great library!

    I'm working on a system that's dealing with both fiat currencies and a couple of cryptocurrencies and I thought I could easily build a Locale object to describe common crypto formats (all decimal places, symbol after the number, etc)

    I have this:

    var cryptos = map[string]accounting.Locale{
    	"USDC": {
    		Name:           "USD Coin",
    		FractionLength: 11,
    		ThouSep:        ",",
    		DecSep:         ".",
    		SpaceSep:       " ",
    		UTFSymbol:      "",
    		HTMLSymbol:     "",
    		ComSymbol:      "USDC",
    		Pre:            false,
    	},
    }
    

    But then I realised, the actual formatting API doesn't accept some of these parameters, most importantly Pre which I wanted to use to place the symbol after the value, which seems to be the consensus around crypto currency value formatting:

    123.435 USDC
    

    For example.

    It seems this could be implemented in the formatMoneyString function if Accounting had a Pre field.

    Though, it also begs the question, why not just embed Locale into Accounting?

    Anyway, would be happy to submit a PR for formatMoneyString!

    opened by Southclaws 0
  • Fraction length wrong

    Fraction length wrong

    @leekchan friend. Hey please take a look at this line https://github.com/leekchan/accounting/blob/17a4ce5f94d4d6b8115c2c6f39f7f2e8cb8f27f0/locale.go#L189

    I think Viet nam Dong has fraction length of 0, not 2 as in your code reference: https://developer.cybersource.com/library/documentation/sbc/quickref/currencies.pdf

    Thank you!

    opened by iamleson98 0
  • [Russian Ruble] symbol after number

    [Russian Ruble] symbol after number

    https://github.com/leekchan/accounting/blob/17a4ce5f94d4d6b8115c2c6f39f7f2e8cb8f27f0/locale.go#L152

    subj

    References: https://core.telegram.org/bots/payments#supported-currencies image image image

    opened by Disinterpreter 5
Releases(v0.3.1)
  • v0.3.1(Aug 6, 2020)

  • v0.3(Dec 24, 2019)

    accounting v0.3 includes many contributions. Thank you to all who have contributed in this great work! 🙇

    🌟 What's New in accounting v0.3

    • https://github.com/leekchan/accounting/pull/7 Support github.com/cockroachdb/apd for BigDecimal numbers (by @tamalsaha)
    • https://github.com/leekchan/accounting/pull/10 Add support for github.com/shopspring/decimal Add support for github.com/shopspring/decimal (by @Dexus)
    • https://github.com/leekchan/accounting/pull/11 Add Function DefaultAccounting and NewAccounting (by @Dexus)
    • https://github.com/leekchan/accounting/pull/13 Go modules (by @akkumar)
    • https://github.com/leekchan/accounting/pull/14 Use formattedNumber to format zero (by @bykof)
    • https://github.com/leekchan/accounting/pull/15 Locale Info and UnformatNumber (by @djackreuter)
    Source code(tar.gz)
    Source code(zip)
  • v0.2(Dec 11, 2016)

  • v0.1(Aug 22, 2015)

    big.Float support has been added

    ac = accounting.Accounting{Symbol: "$", Precision: 2}
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(123456789.213123))) // "$123,456,789.21"
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(12345678)))         // "$12,345,678.00"
    
    ac = accounting.Accounting{Symbol: "€", Precision: 2, Thousand: ".", Decimal: ","}
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(4999.99)))  // "€4.999,99"
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(-4999.99))) // "€-4.999,99"
    
    ac = accounting.Accounting{Symbol: "£ ", Precision: 0}
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(-500000))) // "£ -500,000"
    
    ac = accounting.Accounting{Symbol: "GBP", Precision: 0,
        Format: "%s %v", FormatNegative: "%s (%v)", FormatZero: "%s --"}
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(1000000))) // "GBP 1,000,000"
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(-5000)))   // "GBP (5,000)"
    fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(0)))       // "GBP --"
    
    Source code(tar.gz)
    Source code(zip)
Owner
Kyoung-chan Lee
Kyoung-chan Lee
A currency computations package.

Currency v1.0.0 Currency package helps you do currency computations accurately, by avoiding peddling. The Currency struct holds all the data required

Kamaleshwar 47 Jul 27, 2022
Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Alejandro Pedraza 141 Jun 26, 2022
Go implementation of Fowler's Money pattern

Money GoMoney provides ability to work with monetary value using a currency's smallest unit. This package provides basic and precise Money operations

Raymond 1.1k Aug 3, 2022
Mobile Money API Handyman

pesakit pesakit is a highly configurable commandline tool that comes in handy during testing and development of systems that integrate with mobile mon

TECHCRAFT TECHNOLOGIES LIMITED 2 Nov 22, 2021
Simple and easy to use client for stock market, forex and crypto data from finnhub.io written in Go. Access real-time financial market data from 60+ stock exchanges, 10 forex brokers, and 15+ crypto exchanges

go-finnhub Simple and easy to use client for stock, forex and crpyto data from finnhub.io written in Go. Access real-time market data from 60+ stock e

Miles Croxford 74 Jul 31, 2022
Golang library for querying and parsing OFX

OFXGo OFXGo is a library for querying OFX servers and/or parsing the responses. It also provides an example command-line client to demonstrate the use

Aaron Lindsay 103 Jul 10, 2022
Matching Engine for Limit Order Book in Golang

Go orderbook Improved matching engine written in Go (Golang) Features Standard price-time priority Supports both market and limit orders Supports orde

Karlson Lee 282 Jul 29, 2022
Technical Analysis Library for Golang

Techan TechAn is a technical analysis library for Go! It provides a suite of tools and frameworks to analyze financial data and make trading decisions

Steve Coffey 656 Aug 5, 2022
Package to easily consume the Dolarpy API in golang.

dolarpy-go Package to easily consume the Dolarpy API in golang. https://github.com/melizeche/dolarPy - by melizeche Install import "github.com/bitebai

bitebait 1 Apr 11, 2022
Go-finproto - a collection of finance-related protocols implemented in Golang

go-finproto go-finproto is a collection of finance-related protocols implemented

Mark Winter 6 Jul 25, 2022
A go port of numpy-financial functions and more.

go-financial This package is a go native port of the numpy-financial package with some additional helper functions. The functions in this package are

Razorpay 269 Aug 1, 2022
This is a backend of wallet app for personal spending and income management.

wallet-ap-graphql this is a backend of wallet app for personal spending and income management. technologies used: golang, graphql, postgres, redis, jw

Jamshid Ismoilov 0 Jan 12, 2022
A command line Crypto-currency ticker made using golang and WazirX Api

░█████╗░██████╗░██╗░░░██╗██████╗░████████╗███████╗██╗░░██╗ ██╔══██╗██╔══██╗╚██╗░██╔╝██╔══██╗╚══██╔══╝██╔════╝╚██╗██╔╝ ██║░░╚═╝██████╔╝░╚████╔╝░██████╔

Aditya Das 4 Feb 6, 2022
Go client for the Foreign exchange rates and currency conversion API 💰

fixer Go client for Fixer.io (Foreign exchange rates and currency conversion API) You need to register for a free access key if using the default Fixe

Peter Hellberg 18 Jul 3, 2022
Go client for the Foreign exchange rates and currency conversion API moneybag

fixer Go client for Fixer.io (Foreign exchange rates and currency conversion API) You need to register for a free access key if using the default Fixe

Shingirai Chanakira 0 Nov 25, 2021
Prosper - General app launcher with support for translation, calc, currency and unit conversion.

Prosper Description General app launcher with support for translation, calc, currency and unit conversion. Global shortcut is Option (Alt) + Space Fea

Ventsislav Georgiev 11 Jun 17, 2022
:clock1: Date and Time - Golang Formatting Library

Kair Date and Time - Golang Formatting Library Setup To get Kair > Go CLI go get github.com/GuilhermeCaruso/kair > Go DEP dep ensure -add github.com/G

Guilherme Caruso 23 Mar 15, 2022
Currency handling for Go.

currency Handles currency amounts, provides currency information and formatting. Powered by CLDR v38, in just ~30kb of data. Backstory: https://bojanz

Bojan Zivanovic 327 Aug 3, 2022
A currency computations package.

Currency v1.0.0 Currency package helps you do currency computations accurately, by avoiding peddling. The Currency struct holds all the data required

Kamaleshwar 47 Jul 27, 2022
Raymond 1.1k Aug 8, 2022
A reward-based pseudo-currency system built exclusively for IIT Kanpur campus junta.

IITK Coin IITK Coin is a reward-based pseudo-currency system for the IIT Kanpur campus junta. Detailed vision and regulation rules of this currency ar

Bhuvan Singla 26 Apr 29, 2022
Simple user currency module that uses JSON.

UserCurrency Simple user currency module that uses JSON. Install go get github.com/NeutronX-dev/UserCurrency Functions func UserCurrency.Read(path_to

Neutron 1 Nov 23, 2021
Coinbase - You can use this to retrieve the current price for an crypto currency

whats-this You can use this to retrieve the current price for an crypto currency

Manuel 3 Mar 29, 2022
A simple and lightweight library for creating, formatting, manipulating, signing, and validating JSON Web Tokens in Go.

GoJWT - JSON Web Tokens in Go GoJWT is a simple and lightweight library for creating, formatting, manipulating, signing and validating Json Web Tokens

Toby 5 Feb 7, 2022
Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Alejandro Pedraza 141 Jun 26, 2022
Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log me

Seelog project repository 1.6k Aug 1, 2022
Simple library to handle ANSI functions and parsing of color formatting strings

Emerald A basic color library for use in my Go projects, built on top of mgutz/ansi. Package ansi is a small, fast library to create ANSI colored stri

Josh Willox 0 Nov 15, 2021
Go implementation of Fowler's Money pattern

Money GoMoney provides ability to work with monetary value using a currency's smallest unit. This package provides basic and precise Money operations

Raymond 1.1k Aug 3, 2022
Mobile Money API Handyman

pesakit pesakit is a highly configurable commandline tool that comes in handy during testing and development of systems that integrate with mobile mon

TECHCRAFT TECHNOLOGIES LIMITED 2 Nov 22, 2021