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.
Windows, OS X & Linux:
go get github.com/gurre/si
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