Skip to content
/ si Public

Système international (SI) units for Golang

License

Notifications You must be signed in to change notification settings

gurre/si

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mascot
Système international (SI)

GoDoc License Go Report Card

Working with sensors requires some extra thought into how you report measurements. The need for this library arised when several sensors where reporting different units which was confused or hard to distinguish in the backend. E.g. one sensor reporting km/h and another m/s.

Installation

Windows, OS X & Linux:

go get github.com/gurre/si

Usage examples

Simple usage:

// Our sensor reports temperature in millidegrees celcius
mc := si.NewQuantity(si.Milli, si.Temperature)

// Make sure we never forget what unit we are measuring in
temp := si.NewUnit(24062, mc)

fmt.Println(temp)
// 24062 m°C

Combining several quantities:

// NewQuantity takes a prefix and a measure
km := si.NewQuantity(si.Kilo, si.Length)

// Hour is not a SI unit but officially accepted
h := si.NewQuantity(si.Hour, si.Time)

// Combine a value with several SI-units
kmh := si.NewUnit(100, km, h)

parsed := si.Parse(kmh.String())

fmt.Println(kmh, parsed)
// 100.0 km/h 100.0 km/h

More reading

About

Système international (SI) units for Golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages