money

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package money provides the fixed-point representation used by every accounting ledger. One unit is one millionth of a US dollar (microUSD).

Index

Constants

View Source
const MicroPerUSD int64 = 1_000_000

Variables

This section is empty.

Functions

This section is empty.

Types

type MicroUSD

type MicroUSD int64

MicroUSD is an exact, non-floating-point monetary amount.

func Add

func Add(left, right MicroUSD) (MicroUSD, error)

func FromUSD

func FromUSD(value float64) (MicroUSD, error)

FromUSD converts an API-boundary dollar value into fixed-point microUSD. Values are rounded to the public contract's six-decimal precision.

func MustFromUSD

func MustFromUSD(value float64) MicroUSD

MustFromUSD is intended for trusted constants and tests.

func TokenCost

func TokenCost(tokens int64, pricePerMillion MicroUSD) (MicroUSD, error)

TokenCost calculates tokens * price-per-million-tokens without a floating intermediate. Fractions of one microUSD are rounded up so metering never silently undercharges a provider call.

func (MicroUSD) MarshalJSON

func (amount MicroUSD) MarshalJSON() ([]byte, error)

MarshalJSON preserves the existing public costUsd contract while keeping the in-memory representation fixed-point.

func (MicroUSD) USD

func (amount MicroUSD) USD() float64

func (*MicroUSD) UnmarshalJSON

func (amount *MicroUSD) UnmarshalJSON(encoded []byte) error

UnmarshalJSON accepts a JSON dollar number with at most six decimal places.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL