Martinlindhe Unit Save

Conversion of unit library for golang

Project README

About

Travis-CI codecov.io GoDoc

Conversion of unit library for golang

Installation

go get -u github.com/martinlindhe/unit

General use

Basic usage:

ft := 1 * unit.Foot
fmt.Println(ft.Feet(), "feet is", ft.Meters(), "meters")

To use your own data type, you need to convert to the base unit first (eg Length, Speed etc):

type MyUnit int

n := MyUnit(2)
ft := Length(n) * Foot
fmt.Println(ft.Feet(), "feet is", ft.Meters(), "meters")

Temperature

Cannot be used to scale directly like the other units. Instead, use the From* functions to create a Temperature type:

f := unit.FromFahrenheit(100)

fmt.Println("100 fahrenheit in celsius = ", f.Celsius())

Future work

Please note the resulting precision is limited to the float64 type. Big decimal version is being tracked in https://github.com/martinlindhe/unit/issues/3

License

Under MIT

Open Source Agenda is not affiliated with "Martinlindhe Unit" Project. README Source: martinlindhe/unit
Stars
113
Open Issues
4
Last Commit
1 month ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating