From 1addc901bf8782c6d4f6d8333027059ccdb97a9e Mon Sep 17 00:00:00 2001 From: Raimondas Date: Sun, 2 Apr 2017 12:05:32 +0100 Subject: [PATCH 1/2] Update Readme.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c23f641 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Money + +![alt text](http://i.imgur.com/c3XmCC6.jpg "Money") + From 6c263e3d8718b3cbabfaff3028d4a2dda88d389e Mon Sep 17 00:00:00 2001 From: Raimondas Date: Sun, 2 Apr 2017 22:33:50 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/README.md b/README.md index c23f641..829ae18 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,76 @@ ![alt text](http://i.imgur.com/c3XmCC6.jpg "Money") +**GoMoney** provides ability to work with [monetary value using a currency's smallest unit](https://martinfowler.com/eaaCatalog/money.html). +Package allows you to use basic Money operations like rounding, splitting or allocating without losing a penny. +You shouldn't use float for monetary values, since they always carry small rounding differences. + +```go +package main + +import "github.com/rhymond/go-money" + +func main() { + pound := money.New(100, "GBP") + twoPounds := pound.Add(pound) + + parties := twoPounds.Split(3) + parties[0].format() // £0.67 + parties[1].format() // £0.67 + parties[2].format() // £0.66 +} + +``` +## Quick start +Get the package via + +``` bash +$ go get github.com/rhymond/go-money +``` + +## Features +* Provides a Money struct which stores information about an Money amount value and it's currency. +* Provides a ```Money.Amount``` struct which encapsulates all information about a monetary unit. +* Represents monetary values as integers, in cents. This avoids floating point rounding errors. +* Represents currency as ```Money.Currency``` instances providing a high level of flexibility. + +## Usage +### Init +```go +// Initialise Money by using smallest unit value (e.g 100 represents 1 pound) +// and use ISO 4217 Currency Code to set money Currency +pound := money.New(100, "GBP") +``` +### Comparison + +**Go-money** lets you to use base compare operations like: + +* Equals +* GreaterThan +* GreaterThanOrEqual +* LessThan +* LessThanOrEqual +In order to use them currencies must be equal + +```go +// Initialise Money by using smallest unit value (e.g 100 represents 1 pound) +// and use ISO 4217 Currency Code to set money Currency +pound := money.New(100, "GBP") +twoPounds := money.New(200, "GBP") +twoEuros := money.New(200, "EUR") + +pound.GreaterThan(twoPounds) // false +pound.LessThan(twoPounds) // true +twoPounds.Equals(twoEuros) // Error: Currencies don't match +``` + + + + + + + + + + +