Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

martinlindhe/unit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

48 Commits

Repository files navigation

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 #3

License

Under MIT

About

Conversion of unit library for golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

Languages

AltStyle によって変換されたページ (->オリジナル) /