https://github.com/nomad-software/mongo
A straightforward money library for Go
https://github.com/nomad-software/mongo
currency go golang money
Last synced: 10 months ago
JSON representation
A straightforward money library for Go
- Host: GitHub
- URL: https://github.com/nomad-software/mongo
- Owner: nomad-software
- License: mit
- Created: 2021-03-06T16:48:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T19:06:22.000Z (over 3 years ago)
- Last Synced: 2025-07-19T15:52:12.960Z (11 months ago)
- Topics: currency, go, golang, money
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongo
**A straightforward money library for Go**
---
## Overview
Mongo is a straightforward money library for Go that makes it easy to handle the
usually bug prone arithmetic when dealing with money.
## Documentation
https://pkg.go.dev/github.com/nomad-software/mongo@master#section-documentation
## Example 1
```go
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/nomad-software/mongo"
)
func main() {
m, err := mongo.MoneyGBP(1055)
if err != nil {
log.Fatal("Error occured creating money")
}
fmt.Printf("Money: %s\n", m)
shares := m.Split(3)
fmt.Printf("Shares: %s\n", shares)
shares = m.Allocate(1, 2, 3)
fmt.Printf("Allocations: %s\n", shares)
json, _ := json.Marshal(m)
fmt.Println(string(json))
}
```
### Output
```
Money: £10.55
Shares: [£3.52 £3.52 £3.51]
Allocations: [£1.76 £3.52 £5.27]
{"currency":"GBP","amount":"£10.55"}
```
## Example 2
```go
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/nomad-software/mongo"
)
func main() {
m, err := mongo.PriceGBP(1055, 17.5)
if err != nil {
log.Fatal("Error occured creating price")
}
fmt.Printf("Price: %s\n", m)
json, _ := json.Marshal(m)
fmt.Println(string(json))
}
```
### Output
```
Price: £10.55
{"currency":"GBP","gross":"£10.55","net":"£8.98","tax":{"total":"£1.57","detail":[{"amount":"£1.57","description":"VAT"}]}}
```