Skip to content

wealdtech/go-string2eth

Repository files navigation

go-string2eth

Tag License GoDoc Travis CI codecov.io Go Report Card

Go utility library to convert strings to Ether values and vice versa.

When converting strings to numeric values the process is case-insensitive and doesn't care about whitespace, so input values such as "0.1 Ether", "0.1Ether" and "0.1ether" would all result in the same result. The standard unit denominations (Wei, Ether) are supported with or without SI prefixes (micro, milli, kilo, mega etc.), as are common names (Shannon, Babbage).

When converting numeric values to strings the user can select standard mode, in which case all values will be in units of Wei or Ether, or non-standard mode, in which case the full range of values will be used.

This also provides the ability to convert between string and GWei values.

Table of Contents

Install

go-string2eth is a standard Go module which can be installed with:

go get github.com/wealdtech/go-string2eth

Usage

go-string2eth converts from strings to Ether values and back again.

Example

package main

import (
	string2eth "github.com/wealdtech/go-string2eth"
)

func main() {

    // Convert a string value to a number of Wei
    value, err := string2eth.StringToWei("0.05 Ether")
    if err != nil {
        panic(err)
    }

    // Convert a number of Wei to a string value
    str := string2eth.WeiToString(value, true)

    fmt.Printf("0.05 Ether is %v Wei, is %s\n", value, str)
}

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2019 Weald Technology Trading Ltd

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages