units

package
v2.0.0-...-2cd5660 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package units provides functions for converting different units of IOTAs.

Index

Examples

Constants

View Source
const (
	// I is the smallest Unit.
	I = Unit(1)
	// Ki = Kiloiota. 1000 iotas.
	Ki = Unit(1000)
	// Mi = Megaiota. 1 million iotas.
	Mi = Unit(1000000)
	// Gi = Gigaiota. 1 billion iotas.
	Gi = Unit(1000000000)
	// Ti = Teraiota. 1 trillion iotas.
	Ti = Unit(1000000000000)
	// Pi = Petaiota. 1 quadrillion iotas.
	Pi = Unit(1000000000000000)
)

Variables

This section is empty.

Functions

func ConvertUnits

func ConvertUnits(val float64, from Unit, to Unit) float64

ConvertUnits converts the given value in the base Unit to the given new Unit.

Example
package main

import (
	"fmt"

	"github.com/GalRogozinski/iota.go/v2/units"
)

func main() {
	conv := units.ConvertUnits(float64(100), units.Mi, units.I)
	fmt.Println(conv)
}
Output:

1e+08

func ConvertUnitsString

func ConvertUnitsString(val string, from Unit, to Unit) (float64, error)

ConvertUnitsString converts the given string value in the base Unit to the given new Unit.

Example
package main

import (
	"fmt"

	"github.com/GalRogozinski/iota.go/v2/units"
)

func main() {
	conv, err := units.ConvertUnitsString("10.1", units.Gi, units.I)
	if err != nil {
		// handle error
		return
	}
	fmt.Println(conv)
}
Output:

1.01e+10

Types

type Unit

type Unit float64

Unit a unit of IOTAs.

Jump to

Keyboard shortcuts

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