Skip to content

Zemanta/money

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

money.Micro

CircleCI

A precise fixed-point Go (golang) package for handling money as int64 supporting up to 6 decimal places. Useful when handling smaller amounts but need precision and fast math operations.

Features

  • Speed and simplicity
  • Support for safe math operations with overflow checking: addition, multiplication and division with rounding
  • JSON marshal/unmarshal
  • Conversion from string and float64
  • Works with integer operations: <, >, ==, etc.

Install

Run go get github.com/Zemanta/money

Usage

package main

import (
	"fmt"
	"log"

	"github.com/Zemanta/money"
)

func main() {
	balance := 100 * money.Dollar

	m, err := money.FromString("0.1")
	if err != nil {
		log.Fatal("Error")
	}

	newBalance := balance - m
	if newBalance < 0 {
		log.Fatal("Not enough money")
	}

	fmt.Println(money.ToString(newBalance))
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages