amount

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// NanoPACPerPAC is the number of NanoPAC in one PAC.
	NanoPACPerPAC = 1e9

	// MaxNanoPAC is the maximum transaction amount allowed in NanoPAC.
	MaxNanoPAC = 42e6 * NanoPACPerPAC
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount int64

Amount represents the atomic unit in Pactus blockchain. Each unit equals to 1e-9 of a PAC.

func FromString

func FromString(str string) (Amount, error)

FromString parses a string representing a value in PAC. It then uses NewAmount to create an Amount based on the parsed floating-point value. If the parsing of the string fails, it returns an error.

func NewAmount

func NewAmount(f float64) (Amount, error)

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

NewAmount is specifically for converting PAC to NanoPAC. For creating a new Amount with an int64 value which denotes a quantity of NanoPAC, do a simple type conversion from type int64 to Amount.

func (Amount) Format

func (a Amount) Format(u Unit) string

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

func (Amount) MulF64

func (a Amount) MulF64(f float64) Amount

MulF64 multiplies an Amount by a floating point value.

func (Amount) String

func (a Amount) String() string

String is the equivalent of calling Format with AmountPAC.

func (Amount) ToNanoPAC

func (a Amount) ToNanoPAC() int64

ToNanoPAC is equivalent to calling ToUnit with AmountNanoPAC. It returns the amount of NanoPAC or atomic unit as a 64-bit integer.

func (Amount) ToPAC

func (a Amount) ToPAC() float64

ToPAC is equivalent to calling ToUnit with AmountPAC.

func (Amount) ToUnit

func (a Amount) ToUnit(u Unit) float64

ToUnit converts a monetary amount counted in Pactus base units to a floating-point value representing an amount of Pactus (PAC).

type Unit

type Unit int

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

const (
	UnitMegaPAC  Unit = 6
	UnitKiloPAC  Unit = 3
	UnitPAC      Unit = 0
	UnitMilliPAC Unit = -3
	UnitMicroPAC Unit = -6
	UnitNanoPAC  Unit = -9
)

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

func (Unit) String

func (u Unit) String() string

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

Jump to

Keyboard shortcuts

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