convert

package
v0.0.0-...-2083224 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

ethunitconv

clone from https://github.com/savier89/ethunitconv

Build Status Go Report Card

Ethereum Wei unit Converter

Features

Convert all Ether units http://ethdocs.org/en/latest/ether.html

Install

go get -v github.com/savier89/ethunitconv

Usage

package main

import (
	"fmt"

	"github.com/savier89/ethunitconv"
)

func main() {
	ether := ethunitconv.FromWei("418160973408927260000000000", "Ether")
	fmt.Println(ether)
	ether2wei := ethunitconv.ToWei(ether, "Ether")
	fmt.Println(ether2wei)
}

Output

$ go run main.go
418160973.4089272600
418160973408927259994095616

$ go test -v
=== RUN   TestConverter
418160973.4089272600
418160973408927259994095616
--- PASS: TestConverter (0.00s)
PASS
ok      github.com/savier89/ethunitconv	0.001s

Donate

You can help fund the developer by donating to the following wallet addresses:

BTC: 1HhcW3NjAswZPGBmHo1Kcr2JPA3cfn1bA6
ETH: 0xF9E93f163E8Bd606BD36CA2D177C345750C66241
CLO: 0x9c0B6195092780963ef2EB978C4b2E1d2f375Bb4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromWei

func FromWei(number string, unitname string) string

FromWei func calculate number / unitfactor return string

func ToWei

func ToWei(number string, unitname string) string

ToWei func calculate number * unitfactor return string

Types

type Factor

type Factor int

Factor type for enum

const (
	// Wei 1 wei
	Wei Factor = 0
	// KWei (babbage) 1e3 wei
	KWei Factor = 3
	// MWei (lovelace) 1e6 wei
	MWei Factor = 6
	// GWei (shannon) 1e9 wei
	GWei Factor = 9
	// Szabo (microether) 1e12 wei
	Szabo Factor = 12
	// Finney (milliether) 1e15 wei
	Finney Factor = 15
	// Ether 1e18 wei
	Ether Factor = 18
	// KEther 1e21 wei
	KEther Factor = 21
	// MEther 1e24 wei
	MEther Factor = 24
	// GEther 1e27 wei
	GEther Factor = 27
)

type Unit

type Unit struct {
	Name      string
	WeiFactor *big.Int
}

Unit Base struct

func (*Unit) GetWeiFactor

func (unit *Unit) GetWeiFactor() *big.Int

GetWeiFactor func return unit.WeiFactor

func (*Unit) InitUnit

func (unit *Unit) InitUnit(unitname string) *Unit

InitUnit func param unitname(string) retun Unit struct by default Wei factor

Jump to

Keyboard shortcuts

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