Skip to content

eapenkin/govalues-money

 
 

Repository files navigation

Money

githubb codecovb goreportb godocb licenseb versionb

Package money implements immutable monetary amounts for Go.

Getting started

To install the money package into your Go workspace, you can use the go get command:

go get github.com/govalues/money

To use the money package in your Go project, you can import it as follows:

import (
    "github.com/govalues/decimal"
    "github.com/govalues/money"
)

Using Amount

To create a new amount, you can use one of the provided constructors, such as NewAmount, MustNewAmount, ParseAmount or MustParseAmount.

d := decimal.MustNew(12345, 2)              // d = 123.45
a := money.MustNewAmount(money.USD, d)      // a = USD 123.45
b := money.MustParseAmount("USD", "123.45") // b = USD 123.45

Once you have an amount, you can perform arithmetic operations such as addition, subtraction, multiplication, division, as well as rounding operations such as ceiling, floor, truncation, and rounding.

sum, _ := a.Add(b)
difference, _ := a.Sub(b)
product, _ := a.Mul(d)
quotient, _ := a.Quo(d)
ratio, _ := a.Rat(b)
ceil := a.Ceil(2)
floor := a.Floor(2)
trunc := a.Trunc(2)
round := a.Round(2)

For more details on these and other methods, see the package documentation at pkg.go.dev.

Benchmarks

For the benchmark results please check description of decimal package.

Contributing to the project

The money package is hosted on GitHub. To contribute to the project, follow these steps:

  1. Fork the repository and clone it to your local machine.
  2. Make the desired changes to the code.
  3. Write tests for the changes you made.
  4. Ensure that all tests pass by running go test.
  5. Commit the changes and push them to your fork.
  6. Submit a pull request with a clear description of the changes you made.
  7. Wait for the maintainers to review and merge your changes.

Note: Before making any significant changes to the code, it is recommended to open an issue to discuss the proposed changes with the maintainers. This will help to ensure that the changes align with the project's goals and roadmap.

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%