Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

0x4A756E65/bps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bps

bps banner

Slim Go helper for basis-point fees on integer amounts (cents/token units) with deterministic floor rounding.

Install

go get github.com/0x4A756E65/bps

Usage

package main

import (
	"fmt"

	"github.com/0x4A756E65/bps"
)

func main() {
	amount := int64(10_000) // 100.00 units
	rate := bps.BPS(25)     // 25 bps = 0.25%

	fee := bps.Apply(amount, rate)      // 25
	net, fee := bps.Net(amount, rate)   // 9_975, 25
	gross, fee := bps.GrossFromNet(10_000, rate) // 10_025, 25

	layered := bps.Sum(15, 10, 5)       // 30 bps
	_, _ = bps.Net(amount, layered)
	fmt.Println(fee, net, gross, layered)
}

Helpers:

  • Apply(amount, rate) computes the fee.
  • Net(amount, rate) returns the post-fee amount and fee.
  • GrossFromNet(net, rate) finds the minimal gross that still yields your target net after fees.
  • Sum(rates...) composes layered fees.

Examples

go run ./examples/basic

Testing

go test ./...

License

MIT

About

Slim Go helper for basis-point fees on integer amounts (cents/token units) with deterministic floor rounding.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages