https://github.com/martinlindhe/unit
Conversion of unit library for golang
https://github.com/martinlindhe/unit
conversion golang units-of-measure
Last synced: 6 months ago
JSON representation
Conversion of unit library for golang
- Host: GitHub
- URL: https://github.com/martinlindhe/unit
- Owner: martinlindhe
- License: mit
- Created: 2016-03-01T17:08:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-12T19:26:04.000Z (over 1 year ago)
- Last Synced: 2025-04-02T10:46:44.472Z (6 months ago)
- Topics: conversion, golang, units-of-measure
- Language: Go
- Size: 66.4 KB
- Stars: 117
- Watchers: 6
- Forks: 22
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# About
[](https://travis-ci.org/martinlindhe/unit)
[](https://codecov.io/github/martinlindhe/unit?branch=master)
[](https://godoc.org/github.com/martinlindhe/unit)Conversion of unit library for golang
## Installation
```
go get -u github.com/martinlindhe/unit
```## General use
Basic usage:
```go
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):
```go
type MyUnit intn := 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:```go
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](LICENSE)