unit

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: LGPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drip

type Drip struct {
	// contains filtered or unexported fields
}

Drip is minimal unit of conflux network coin, 1CFX = 10^18 DRIP

func NewDrip

func NewDrip(value *big.Int) *Drip

func NewDripFromString

func NewDripFromString(prettyValue string) (*Drip, error)

NewDripFromString create Drip from string, prettyValue could be one part or two parts, if one part like "12345" that equals to "12345 Drip", if two parts like "1.2 CFX", the second part is unit

NewDripFromString("12345") => 12345 Drip
NewDripFromString("1.2 CFX") => 1.2 CFX

func (*Drip) BigInt

func (d *Drip) BigInt() *big.Int

BigInt return drip value as big.Int

func (*Drip) Cmp

func (d *Drip) Cmp(y *Drip) int

Cmp compare drip value with another drip value

func (*Drip) Format

func (d *Drip) Format(unit UnitType) decimal.Decimal

Format format drip to value with unit

d := NewDrip(big.NewInt(1000000000))
d.Format(UNIT_CFX) => 0.0000000001

func (*Drip) FormatCFX

func (d *Drip) FormatCFX() decimal.Decimal

FormatCFX format drip to value with unit CFX

d := NewDrip(big.NewInt(1000000000))
d.Format() => 0.0000000001

func (*Drip) ParseFrom

func (d *Drip) ParseFrom(value decimal.Decimal, unit UnitType) error

ParseFrom parse drip from value with uint

ParseFrom(10, UNIT_GCFX) => 10_000_000_000 Drip

func (*Drip) ParseFromCFX

func (d *Drip) ParseFromCFX(value decimal.Decimal) error

ParseFrom same to ParseFrom and unit is CFX

ParseFrom(10) => 10_000_000_000 Drip

func (Drip) String

func (d Drip) String() string

String implements Stringer interface

type UnitType

type UnitType int32
const (
	UNIT_CFX   UnitType = 18
	UNIT_mCFX  UnitType = 15
	UNIT_uCFX  UnitType = 12
	UNIT_GDrip UnitType = 9
	UNIT_MDrip UnitType = 6
	UNIT_KDrip UnitType = 3
	UNIT_Drip  UnitType = 0
)

func ParseUnitType

func ParseUnitType(unitName string) (*UnitType, error)

func (UnitType) String

func (u UnitType) String() string

Jump to

Keyboard shortcuts

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