amount

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AmountMegaBTC  Unit = 6
	AmountKiloBTC  Unit = 3
	AmountBTC      Unit = 0
	AmountMilliBTC Unit = -3
	AmountMicroBTC Unit = -6
	AmountSatoshi  Unit = -8

	CENT int64 = 1000000
)

These constants define various units used when describing a bitcoin monetary amount.

Variables

This section is empty.

Functions

func MoneyRange

func MoneyRange(value Amount) bool

Types

type Amount

type Amount int64

Amount represents the base bitcoin monetary unit (colloquially referred to as a `Satoshi'). A single Amount is equal to 1e-8 of a bitcoin.

func NewAmount

func NewAmount(f float64) (Amount, error)

NewAmount creates an Amount from a floating point value representing some value in bitcoin. NewAmount errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of bitcoin producible as f may not refer to an amount at a single moment in time.

NewAmount is for specifically for converting BTC to Satoshi. For creating a new Amount with an int64 value which denotes a quantity of Satoshi, do a simple type conversion from type int64 to Amount. See GoDoc for example: http://godoc.org/github.com/btcsuite/btcutil#example-Amount

func (Amount) Format

func (a Amount) Format(u Unit) string

Format formats a monetary amount counted in bitcoin base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "Satoshi" for the base unit.

func (Amount) MulF64

func (a Amount) MulF64(f float64) Amount

MulF64 multiplies an Amount by a floating point value. While this is not an operation that must typically be done by a full node or wallet, it is useful for services that build on top of bitcoin (for example, calculating a fee by multiplying by a percentage).

func (Amount) String

func (a Amount) String() string

String is the equivalent of calling Format with AmountBTC.

func (Amount) ToBTC

func (a Amount) ToBTC() float64

ToBTC is the equivalent of calling ToUnit with AmountBTC.

func (Amount) ToUnit

func (a Amount) ToUnit(u Unit) float64

ToUnit converts a monetary amount counted in bitcoin base units to a floating point value representing an amount of bitcoin.

type Unit

type Unit int

Unit describes a method of converting an Amount to something other than the base unit of a bitcoin. The value of the Unit is the exponent component of the decadic multiple to convert from an amount in bitcoin to an amount counted in units.

func (Unit) String

func (u Unit) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Satoshi" for the base unit. For all unrecognized units, "1eN BTC" is returned, where N is the Unit.

Jump to

Keyboard shortcuts

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