Slim Go helper for basis-point fees on integer amounts (cents/token units) with deterministic floor rounding.
go get github.com/0x4A756E65/bps
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.
go run ./examples/basic
go test ./...
MIT