currency

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package currency implements the type PicoDollar and MicroDollar, and its conversions.

Index

Constants

View Source
const (
	MicroDollarsPerDollar = 1e6
	PicoDollarsPerDollar  = 1e12
)

Variables

This section is empty.

Functions

func FromWei added in v1.0.0

func FromWei(wei *big.Int, decimals int) string

FromWei converts a wei value into a decimal string with the given decimals. For ETH, use decimals = 18. For an ERC20, use its `decimals()` value.

Types

type MicroDollar added in v0.5.1

type MicroDollar int64

PicoDollar is a type to represent currency with 12 decimal precision

func (MicroDollar) ToBigInt added in v0.5.1

func (m MicroDollar) ToBigInt() *big.Int

type PicoDollar

type PicoDollar int64

PicoDollar is a type to represent currency with 12 decimal precision

func FromDollars

func FromDollars(dollars float64) (PicoDollar, error)

FromDollars converts a dollar amount (as a float) to Picodollars This should mostly be used for testing, and real usage should be done purely in PicoDollars

func FromMicrodollars added in v0.5.1

func FromMicrodollars(microdollars MicroDollar) PicoDollar

FromMicrodollars converts an int64 microdollar amount to PicoDollar

func (PicoDollar) String

func (p PicoDollar) String() string

func (PicoDollar) ToDollars added in v1.0.0

func (p PicoDollar) ToDollars() float64

ToDollars converts PicoDollars to a dollar amount (as a float)

func (PicoDollar) ToMicroDollars

func (p PicoDollar) ToMicroDollars() MicroDollar

ToMicroDollars converts PicoDollars to MicroDollars (1e6 units per dollar)

Jump to

Keyboard shortcuts

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