Skip to content
/ unit Public
forked from martinlindhe/unit

Conversion of unit library for golang

License

Notifications You must be signed in to change notification settings

foxmeder/unit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

GoDoc

Conversion of unit library for golang

forked from martinlindhe/unit

new feature

Add more unit including common unit from China

New function UnitConv to do conversion conveniently

Installation

go get -u github.com/foxmeder/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")

Conversion func usage:

from and to use format of dimension.name,see dimension list for details

For example:use pressure.atm for Atmosphere

from := "pressure.atm"
to := "pressure.mmhg"
result,err := unit.UnitConv(from, to, 100)

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

License

Under MIT

About

Conversion of unit library for golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%