money

package
v1.64.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount[T any] interface {
	String() string
	Compare(T) int
}

type Options

type Options struct {
	Amount        string
	Currency      string
	DecimalPlaces int
}

type Value

type Value[T Amount[T]] struct {
	// contains filtered or unexported fields
}

func New

func New[T Amount[T]](opts Options, parse func(string) (T, error)) (Value[T], error)

func (Value[T]) Amount

func (m Value[T]) Amount() T

func (Value[T]) Cmp

func (m Value[T]) Cmp(other Value[T]) (int, error)

func (Value[T]) Combine

func (m Value[T]) Combine(other Value[T], op func(T, T) T) (Value[T], error)

Combine applies op to two amounts of the same currency; the result keeps the wider display places.

func (Value[T]) Currency

func (m Value[T]) Currency() string

func (Value[T]) DecimalPlaces

func (m Value[T]) DecimalPlaces() int

func (Value[T]) MarshalJSON

func (m Value[T]) MarshalJSON() ([]byte, error)

func (Value[T]) MarshalText

func (m Value[T]) MarshalText() ([]byte, error)

func (Value[T]) String

func (m Value[T]) String() string

String formats an uninitialized value as an empty string; MarshalJSON and Validate still reject it.

func (Value[T]) Validate

func (m Value[T]) Validate() error

func (Value[T]) WithAmount

func (m Value[T]) WithAmount(amount T) (Value[T], error)

WithAmount returns amount in m's currency with at least m's display places.

Jump to

Keyboard shortcuts

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