Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
/ go-decimal Public archive

go decimal package suitable for financial and monetary calculations

License

Notifications You must be signed in to change notification settings

dimdin/go-decimal

Repository files navigation

decimal

go decimal package suitable for financial and monetary calculations

Build Status

Installation

go get github.com/dimdin/decimal

Documentation

Documentation and usage examples

Usage

import "github.com/dimdin/decimal"

    var x, y decimal.Dec
    x.SetString("100")
    y.SetString("3")
    x.Div(&x, &y, 2)
    fmt.Println(x)

Output:

33.33

Features

  • 38 decimal digits precision implemented with an 128 bit integer scaled by a power of ten.
  • Fast addition, subtraction, multiplication, division and power operations.
  • Arithmetic overflow detection that panics.
  • Can be scanned directly from database/sql query results.
  • Can be used directly in database/sql Query and Exec parameters.
  • Methods are in the math/big form func (z *Dec) Op(x, y *Dec) *Dec with the result as receiver.
  • Arithmetic half up rounding.
  • Test suite with more than 90% code coverage.

License

Use of this source code is governed by BSD 2-clause license that can be found in the LICENSE file.

About

go decimal package suitable for financial and monetary calculations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages