units

package module
v0.0.0-...-be29ffd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 11 Imported by: 0

README

godocs.io

go-units

Go library for manipulating and converting between various units of measurement.

This is a fork of bcicen's go-units package, with significant breaking changes.
You find a list of breaking changes at the bottom of this page.

Principles

  • Name and Aliases are case-insensitive
  • Symbols are case-sensitive (e.g. MegaMeter Mm <> MilliMeter mm)
  • Names, symbols and aliases must be unique! => Looking up a unit must return 1 exact match!

Usage

In the most basic usage, go-units may be used to convert a value from one unit to another:

package main

import (
	"fmt"
	u "github.com/woweh/go-units"
)

func main() {
	// convert a simple float from celsius to fahrenheit
	fmt.Println(u.MustConvertFloat(25.5, u.Celsius, u.Fahrenheit)) // outputs "77.9 fahrenheit"

	// convert a units.Value instance
	val := u.NewValue(25.5, u.Celsius)

	fmt.Println(val)                           // "25.5 celsius"
	fmt.Println(val.MustConvert(u.Fahrenheit)) // "77.9 fahrenheit"
	fmt.Println(val.MustConvert(u.Kelvin))     // "298.65 kelvin"
}
Formatting

Aside from unit conversions, go-units may also be used for generating human-readable unit labels, plural names, and symbols:

val := u.NewValue(2.0, u.Nibble)
fmt.Println(val)                     // "2 nibbles"
fmt.Println(val.MustConvert(u.Byte)) // "1 byte"

// value formatting options may also be specified:
opts := u.FmtOptions{
  Label:     true, // append unit name/symbol
  Short:     true, // use unit symbol
  Precision: 3,
}

val = u.NewValue(15.456932, u.KiloMeter)
fmt.Println(val)           // "15.456932 kilometers"
fmt.Println(val.Fmt(opts)) // "15.457 km"
fmt.Println(val.Float())   // "15.456932"
Lookup

The package-level Find() method may be used to search for a unit by name, symbol, or alternate spelling:

// symbol
unit, err := u.Find("m")
// name
unit, err := u.Find("meter")
// alternate spelling
unit, err := u.Find("metre")
Custom Units

go-units comes with many unit names and symbols builtin; however, new units and conversions can be easily added:

// register custom unit names
Ding := u.NewUnit("ding", "di")
Dong := u.NewUnit("dong", "do")

// there are 100 dongs in a ding
u.NewRatioConversion(Ding, Dong, 100.0)

val := u.NewValue(25.0, Ding)

fmt.Printf("%s = %s\n", val, val.MustConvert(Dong)) // "25 dings = 2500 dongs"

// conversions are automatically registered when using magnitude prefix helper methods
KiloDong := u.Kilo(Dong)
fmt.Println(u.MustConvertFloat(1000.0, Dong, KiloDong)) // "1 kilodong"

You can also add aliases or symbols to existing units:

// add alternative spellings and translations
CubicMeter.AddAliases("cubic metre", "Quadratmeter", "Vierkante meter", "Metr kwadratowy", "Mètre carré")
// add additional symbols
CubicMeter.AddSymbols("m3", "m^3", "m**3", "cum", "cbm", "CBM", "M3")
Notes regarding unit and conversion definitions

When you specify a function conversion (NewConversionFromFn), you must also specify the inverse conversion.

Specifying a ratio conversion (NewRatioConversion) also registers the inverse conversions.
For ratio conversions you don't need to specify the inverse conversions.

The metric factory methods, like u.Kilo, will create the new unit with metric prefixes for name and symbols, and will register ratio conversions between the base unit and the derived metric unit.
There is no need to separately specify the ratio conversion.

Known Issues

Unicode symbols (e.g., , ) can cause panics.
TODO: Investigate and debug.

References / Further Reading

The National Institute of Standards and Technology (NIST) - The NIST Guide for the use of the International System of Units - Appendix B, subsections B.8 Factors for Units Listed Alphabetically and B.9 Factors for units listed by kind of quantity or field of science.

Wikipedia contributors. "Conversion of units" Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia.

https://qudt.org/
The QUDT, or 'Quantity, Unit, Dimension and Type' collection of ontologies define the base classes properties, and restrictions used for modeling physical quantities, units of measure, and their dimensions in various measurement systems. QUDT provides a unified model of measurable quantities, units for measuring different kinds of quantities, the numerical values of quantities in different units of measure and the data structures and data types used to store and manipulate these objects in software. This OWL schema is a foundation for a basic treatment of units. Originally developed by TopQuadrant for the NASA Exploration Initiatives Ontology Models (NExIOM) project, they now form the basis of the NASA QUDT Handbook. QUDT aims to improve interoperability of data and the specification of information structures through industry standards for Units of Measure, Quantity Kinds, Dimensions and Data Types.

There are many online calculators and converters that you can use to cross-check conversions. Many of them provide explanations and formulae,

Breaking Changes compared to bcicen's version
  • Use unit pointers in the unitMap, units have a shared state.
  • Don't panic! AT least, try not to panic. There are still three methods that do panic:
    1. unit.newUnit - the private, internal factory to create new units => find duplicate names or symbols at compile time
    2. value.MustConvert
    3. units.MustConvertFloat
  • Change the signature of NewUnit, return (*Unit, error) instead of Unit.
  • Extend the Unit struct to support alternative symbols.
  • Symbols are case-sensitive.
  • Names, symbols and aliases must be unique!
    Before, only names had to be unique.
  • Add types for UnitSystem and UnitQuantity
Changes and Enhancements
  • Many additional units
  • Add methods to add aliases and symbols to units
  • Add methods to check if a unit has an alias or unit
  • Add methods to get a list of all unit names, symbols and aliases as CSV (> units.GetCsv())
  • Moved conversion tests into separate, per quantity, tests
Ideas

Documentation

Overview

Package units is a library for looking up units, and for manipulating and converting between various units of measurement.

Index

Constants

View Source
const (
	// PluralNone is a keyword for a unit that has no plural
	PluralNone = "<|_none_|>"
	// PluralAuto is a keyword for a unit that has an auto-generated plural
	PluralAuto = "<|_auto_|>"
)
View Source
const CsvHeader = "Name,Symbol,PluralName,Quantity,System,Aliases & Symbols"

CsvHeader is the header row for the CSV output (> see func GetCsv). It matches the format of the Unit.CsvLine method.

Variables

View Source
var (
	Angle = Quantity("angle")

	Turn = newUnit("turn", "tr", Angle)

	Radian      = newUnit("radian", "rad", Angle, SI)
	MilliRadian = Milli(Radian)
	MicroRadian = Micro(Radian)

	// Degree (= decimal degree) is a unit of angle equal to 1/360 of a circle.
	Degree = newUnit("degree", "°", Angle)

	Gon      = newUnit("gon", "gon", Angle, Symbols("grad"))
	DeciGon  = Deci(Gon)
	CentiGon = Centi(Gon)
	MilliGon = Milli(Gon)
	MicroGon = Micro(Gon)
	NanoGon  = Nano(Gon)
	PicoGon  = Pico(Gon)
	FemtoGon = Femto(Gon)
	AttoGon  = Atto(Gon)
	ZeptoGon = Zepto(Gon)
	YoctoGon = Yocto(Gon)
	DecaGon  = Deca(Gon)
	HectoGon = Hecto(Gon)
	KiloGon  = Kilo(Gon)
	MegaGon  = Mega(Gon)
	GigaGon  = Giga(Gon)
	TeraGon  = Tera(Gon)
	PetaGon  = Peta(Gon)
)
View Source
var (
	Area = Quantity("area")

	// metric
	SquareMilliMeter = newUnit("square millimeter", "mm²", Area, SI)
	SquareCentiMeter = newUnit("square centimeter", "cm²", Area, SI)
	SquareDeciMeter  = newUnit("square decimeter", "dm²", Area, SI)
	SquareMeter      = newUnit("square meter", "m²", Area, SI)
	SquareDecaMeter  = newUnit("square decameter", "dam²", Area, SI)
	SquareHectoMeter = newUnit("square hectometer", "hm²", Area, SI)
	SquareKiloMeter  = newUnit("square kilometer", "km²", Area, SI)

	// imperial
	SquareMile = newUnit("square mile", "mi²", Area, BI)
	Acre       = newUnit("acre", "ac", Area, BI)
	SquareInch = newUnit("square inch", "in²", Area, BI)
	SquareFoot = newUnit("square foot", "ft²", Area, BI)
	SquareYard = newUnit("square yard", "yd²", Area, BI)
)
View Source
var (
	Bi   = Quantity("bits")
	Data = Quantity("bytes")

	Byte      = newUnit("byte", "B", Data)
	KiloByte  = newUnit("kilobyte", "KB", Data)
	MegaByte  = newUnit("megabyte", "MB", Data)
	GigaByte  = newUnit("gigabyte", "GB", Data)
	TeraByte  = newUnit("terabyte", "TB", Data)
	PetaByte  = newUnit("petabyte", "PB", Data)
	ExaByte   = newUnit("exabyte", "", Data)
	ZettaByte = newUnit("zettabyte", "", Data)
	YottaByte = newUnit("yottabyte", "", Data)

	Kibibyte = newUnit("kibibyte", "KiB", Data, IEC)
	Mebibyte = newUnit("mebibyte", "MiB", Data, IEC)
	Gibibyte = newUnit("gibibyte", "GiB", Data, IEC)
	Tebibyte = newUnit("tebibyte", "TiB", Data, IEC)
	Pebibyte = newUnit("pebibyte", "PiB", Data, IEC)
	Exbibyte = newUnit("exbibyte", "EiB", Data, IEC)
	Zebibyte = newUnit("zebibyte", "ZiB", Data, IEC)
	Yobibyte = newUnit("yobibyte", "YiB", Data, IEC)

	Bit     = newUnit("bit", "b", Bi)
	KiloBit = Kilo(Bit)
	MegaBit = Mega(Bit)
	GigaBit = Giga(Bit)
	TeraBit = Tera(Bit)
	PetaBit = Peta(Bit)
	ExaBit  = Exa(Bit)

	Nibble = newUnit("nibble", "", Data)
)
View Source
var (
	Density = Quantity("density")

	// metric
	GramPerCubicCentimeter     = newUnit("gram per cubic centimeter", "g/cm³", Density, SI)
	KilogramPerCubicCentimeter = newUnit("kilogram per cubic centimeter", "kg/cm³", Density, SI)
	GramPerCubicMeter          = newUnit("gram per cubic meter", "g/m³", Density, SI)
	KilogramPerCubicMeter      = newUnit("kilogram per cubic meter", "kg/m³", Density, SI)
	GramPerMilliliter          = newUnit("gram per milliliter", "g/mL", Density, SI)
	GramPerLiter               = newUnit("gram per liter", "g/L", Density, SI)
	KilogramPerLiter           = newUnit("kilogram per liter", "kg/L", Density, SI)

	// imperial
	OuncePerCubicInch = newUnit("ounce per cubic inch", "oz/in³", Density, BI)
	OuncePerCubicFoot = newUnit("ounce per cubic foot", "oz/ft³", Density, BI)
	OuncePerGallon    = newUnit("ounce per gallon", "oz/gal", Density, BI)
	PoundPerCubicInch = newUnit("pound per cubic inch", "lb/in³", Density, BI)
	PoundPerCubicFoot = newUnit("pound per cubic foot", "lb/ft³", Density, BI)
	PoundPerGallon    = newUnit("pound per gallon", "lb/gal", Density, BI)
	SlugPerCubicFoot  = newUnit("slug per cubic foot", "slug/ft³", Density, BI)
	TonPerCubicYard   = newUnit("ton per cubic yard", "l ton/yd³", Density, BI)
)
View Source
var (
	DimensionlessRatio = Quantity("dimensionless ratio")

	Fraction         = newUnit("fraction", "", DimensionlessRatio, Plural(PluralNone))
	Percent          = newUnit("percent", "", DimensionlessRatio, Plural(PluralNone))
	Permille         = newUnit("permille", "", DimensionlessRatio, Plural(PluralNone))
	PartsPerMillion  = newUnit("partsPerMillion", "", DimensionlessRatio, Plural(PluralNone))
	PartsPerBillion  = newUnit("partsPerBillion", "", DimensionlessRatio, Plural(PluralNone))
	PartsPerTrillion = newUnit("partsPerTrillion", "", DimensionlessRatio, Plural(PluralNone))
)
View Source
var (
	ElectricCharge = Quantity("electric charge")

	// SI unit metric
	Coulomb      = newUnit("coulomb", "C", ElectricCharge, SI)
	ExaCoulomb   = Exa(Coulomb)
	PetaCoulomb  = Peta(Coulomb)
	TeraCoulomb  = Tera(Coulomb)
	GigaCoulomb  = Giga(Coulomb)
	MegaCoulomb  = Mega(Coulomb)
	KiloCoulomb  = Kilo(Coulomb)
	HectoCoulomb = Hecto(Coulomb)
	DecaCoulomb  = Deca(Coulomb)
	DeciCoulomb  = Deci(Coulomb)
	CentiCoulomb = Centi(Coulomb)
	MilliCoulomb = Milli(Coulomb)
	MicroCoulomb = Micro(Coulomb)
	NanoCoulomb  = Nano(Coulomb)
	PicoCoulomb  = Pico(Coulomb)
	FemtoCoulomb = Femto(Coulomb)
	AttoCoulomb  = Atto(Coulomb)

	AmpereHour      = newUnit("ampere-hour", "A·h", ElectricCharge, SI, Symbols("A⋅h", "A*h", "A.h", "Ah", "AHr"))
	KiloAmpereHour  = Kilo(AmpereHour)
	MilliAmpereHour = Milli(AmpereHour)

	AmpereMinute = newUnit(
		"ampere-minute", "A·min", ElectricCharge, SI, Symbols("A⋅min", "A*min", "A.min", "Amin"),
	)
	KiloAmpereMinute  = Kilo(AmpereMinute)
	MilliAmpereMinute = Milli(AmpereMinute)

	AmpereSecond      = newUnit("ampere-second", "A·s", ElectricCharge, SI, Symbols("A⋅s", "A*s", "A.s", "As"))
	KiloAmpereSecond  = Kilo(AmpereSecond)
	MilliAmpereSecond = Milli(AmpereSecond)
)
View Source
var (
	ElectricCurrent = Quantity("electric current")

	// metric
	Ampere      = newUnit("ampere", "A", ElectricCurrent, SI)
	MilliAmpere = Milli(Ampere)
	MicroAmpere = Micro(Ampere)
	NanoAmpere  = Nano(Ampere)
	PicoAmpere  = Pico(Ampere)
	FemtoAmpere = Femto(Ampere)
	AttoAmpere  = Atto(Ampere)
	ZeptoAmpere = Zepto(Ampere)
	YoctoAmpere = Yocto(Ampere)
	KiloAmpere  = Kilo(Ampere)
	MegaAmpere  = Mega(Ampere)
	GigaAmpere  = Giga(Ampere)
	TeraAmpere  = Tera(Ampere)
	PetaAmpere  = Peta(Ampere)
	ExaAmpere   = Exa(Ampere)
	ZettaAmpere = Zetta(Ampere)
	YottaAmpere = Yotta(Ampere)
)
View Source
var (
	ElectricalResistance = Quantity("electrical resistance")

	Ohm      = newUnit("ohm", "Ω", ElectricalResistance, SI, Symbols("Ω"))
	DecaOhm  = Deca(Ohm)
	HectoOhm = Hecto(Ohm)
	KiloOhm  = Kilo(Ohm)
	MegaOhm  = Mega(Ohm)
	GigaOhm  = Giga(Ohm)
	TeraOhm  = Tera(Ohm)
	PetaOhm  = Peta(Ohm)
	ExaOhm   = Exa(Ohm)
	ZettaOhm = Zetta(Ohm)
	YottaOhm = Yotta(Ohm)
	DeciOhm  = Deci(Ohm)
	CentiOhm = Centi(Ohm)
	MilliOhm = Milli(Ohm)
	MicroOhm = Micro(Ohm)
	NanoOhm  = Nano(Ohm)
	PicoOhm  = Pico(Ohm)
	FemtoOhm = Femto(Ohm)
	AttoOhm  = Atto(Ohm)
	ZeptoOhm = Zepto(Ohm)
	YoctoOhm = Yocto(Ohm)
)
View Source
var (
	Energy = Quantity("energy")

	// metric
	Joule      = newUnit("joule", "J", Energy, SI)
	KiloJoule  = Kilo(Joule)
	MegaJoule  = Mega(Joule)
	GigaJoule  = Giga(Joule)
	TeraJoule  = Tera(Joule)
	PetaJoule  = Peta(Joule)
	ExaJoule   = Exa(Joule)
	ZettaJoule = Zetta(Joule)
	YottaJoule = Yotta(Joule)
	MilliJoule = Milli(Joule)
	MicroJoule = Micro(Joule)
	NanoJoule  = Nano(Joule)
	PicoJoule  = Pico(Joule)
	FemtoJoule = Femto(Joule)
	AttoJoule  = Atto(Joule)

	WattHour = newUnit(
		"watt-hour", "Wh", Energy, SI,
		Aliases("volt ampere hour", "volt ampere reactive hour", "volt ampere hour (reactive)"),
		Symbols("VAh", "varh", "V⋅A⋅hr", "V.A.h", "V.A{reactive}.h", "V⋅A{reactive}⋅hr"),
	)
	KiloWattHour = Kilo(WattHour)
	MegaWattHour = Mega(WattHour)
	GigaWattHour = Giga(WattHour)
	TeraWattHour = Tera(WattHour)
	PetaWattHour = Peta(WattHour)

	// other
	ElectronVolt     = newUnit("electronvolt", "eV", Energy)
	KiloElectronVolt = Kilo(ElectronVolt)
	MegaElectronVolt = Mega(ElectronVolt)
	GigaElectronVolt = Giga(ElectronVolt)

	Calorie     = newUnit("calorie", "cal", Energy)
	KiloCalorie = Kilo(Calorie)
)
View Source
var (
	Force = Quantity("force")

	Newton      = newUnit("newton", "N", Force, SI)
	CentiNewton = Centi(Newton)
	DeciNewton  = Deci(Newton)
	MilliNewton = Milli(Newton)
	MicroNewton = Micro(Newton)
	NanoNewton  = Nano(Newton)
	PicoNewton  = Pico(Newton)
	FemtoNewton = Femto(Newton)
	AttoNewton  = Atto(Newton)
	ZeptoNewton = Zepto(Newton)
	YoctoNewton = Yocto(Newton)
	DecaNewton  = Deca(Newton)
	HectoNewton = Hecto(Newton)
	KiloNewton  = Kilo(Newton)
	MegaNewton  = Mega(Newton)
	GigaNewton  = Giga(Newton)
	TeraNewton  = Tera(Newton)
	PetaNewton  = Peta(Newton)
	ExaNewton   = Exa(Newton)
	ZettaNewton = Zetta(Newton)
	YottaNewton = Yotta(Newton)

	PoundForce = newUnit("pound force", "lbf", Force, BI, Plural(PluralNone))

	Dyne = newUnit("dyne", "dyn", Force, CGS)

	Poundal = newUnit("poundal", "pdl", Force, US)

	KilogramForce = newUnit("kilogram-force", "kgf", Force, MKpS)
	TonneForce    = newUnit("tonne-force", "tf", Force, MKpS)
)
View Source
var (
	Frequency = Quantity("frequency")

	Hertz      = newUnit("hertz", "Hz", Frequency, SI)
	DecaHertz  = Deca(Hertz)
	HectoHertz = Hecto(Hertz)
	KiloHertz  = Kilo(Hertz)
	MegaHertz  = Mega(Hertz)
	GigaHertz  = Giga(Hertz)
	TeraHertz  = Tera(Hertz)
	PetaHertz  = Peta(Hertz)
	ExaHertz   = Exa(Hertz)
	ZettaHertz = Zetta(Hertz)
	YottaHertz = Yotta(Hertz)
	DeciHertz  = Deci(Hertz)
	CentiHertz = Centi(Hertz)
	MilliHertz = Milli(Hertz)
	MicroHertz = Micro(Hertz)
	NanoHertz  = Nano(Hertz)
	PicoHertz  = Pico(Hertz)
	FemtoHertz = Femto(Hertz)
	AttoHertz  = Atto(Hertz)
	ZeptoHertz = Zepto(Hertz)
	YoctoHertz = Yocto(Hertz)

	RadianPerSecond = newUnit("radian per second", "rad/s", Frequency, SI)
	RadianPerMinute = newUnit("radian per minute", "rad/min", Frequency, SI)
	RadianPerHour   = newUnit("radian per hour", "rad/h", Frequency, SI)
	RadianPerDay    = newUnit("radian per day", "rad/d", Frequency, SI)

	DegreePerSecond = newUnit("degree per second", "°/s", Frequency, BI)
	DegreePerMinute = newUnit("degree per minute", "°/min", Frequency, BI)
	DegreePerHour   = newUnit("degree per hour", "°/h", Frequency, BI)
	DegreePerDay    = newUnit("degree per day", "°/d", Frequency, BI)

	RevolutionPerSecond = newUnit("revolution per second", "rev/s", Frequency)
	RevolutionPerMinute = newUnit("revolution per minute", "rev/min", Frequency)
	RevolutionPerHour   = newUnit("revolution per hour", "rev/h", Frequency)
	RevolutionPerDay    = newUnit("revolution per day", "rev/d", Frequency)
)
View Source
var (
	Length = Quantity("length")

	// metric
	Meter      = newUnit("meter", "m", Length, SI)
	ExaMeter   = Exa(Meter)
	PetaMeter  = Peta(Meter)
	TeraMeter  = Tera(Meter)
	GigaMeter  = Giga(Meter)
	MegaMeter  = Mega(Meter)
	KiloMeter  = Kilo(Meter)
	HectoMeter = Hecto(Meter)
	DecaMeter  = Deca(Meter)
	DeciMeter  = Deci(Meter)
	CentiMeter = Centi(Meter)
	MilliMeter = Milli(Meter)
	MicroMeter = Micro(Meter)
	NanoMeter  = Nano(Meter)
	PicoMeter  = Pico(Meter)
	FemtoMeter = Femto(Meter)
	AttoMeter  = Atto(Meter)

	Angstrom = newUnit("angstrom", "Å", Length, BI)
	Inch     = newUnit("inch", "in", Length, BI, Plural("inches"))
	Foot     = newUnit("foot", "ft", Length, BI, Plural("feet"))
	Yard     = newUnit("yard", "yd", Length, BI)
	Mile     = newUnit("mile", "mi", Length, BI)
	League   = newUnit("league", "lea", Length, BI)
	Furlong  = newUnit("furlong", "fur", Length, BI)
)
View Source
var (
	Mass = Quantity("mass")

	// metric
	Gram      = newUnit("gram", "g", Mass, SI)
	ExaGram   = Exa(Gram)
	PetaGram  = Peta(Gram)
	TeraGram  = Tera(Gram)
	GigaGram  = Giga(Gram)
	MegaGram  = Mega(Gram)
	KiloGram  = Kilo(Gram)
	HectoGram = Hecto(Gram)
	DecaGram  = Deca(Gram)
	DeciGram  = Deci(Gram)
	CentiGram = Centi(Gram)
	MilliGram = Milli(Gram)
	MicroGram = Micro(Gram)
	NanoGram  = Nano(Gram)
	PicoGram  = Pico(Gram)
	FemtoGram = Femto(Gram)
	AttoGram  = Atto(Gram)

	// imperial
	Grain  = newUnit("grain", "gr", Mass, BI)
	Drachm = newUnit("drachm", "dr", Mass, BI)
	Ounce  = newUnit("ounce", "oz", Mass, BI)
	Pound  = newUnit("pound", "lb", Mass, BI)
	Stone  = newUnit("stone", "st", Mass, BI)
	Ton    = newUnit("ton", "LT", Mass, BI)
	Slug   = newUnit("slug", "", Mass, BI)
)
View Source
var (
	Power = Quantity("power")

	// metric
	Watt      = newUnit("watt", "W", Power, SI)
	DeciWatt  = Deci(Watt)
	CentiWatt = Centi(Watt)
	MilliWatt = Milli(Watt)
	MicroWatt = Micro(Watt)
	NanoWatt  = Nano(Watt)
	PicoWatt  = Pico(Watt)
	FemtoWatt = Femto(Watt)
	AttoWatt  = Atto(Watt)
	ZeptoWatt = Zepto(Watt)
	YoctoWatt = Yocto(Watt)
	DecaWatt  = Deca(Watt)
	HectoWatt = Hecto(Watt)
	KiloWatt  = Kilo(Watt)
	MegaWatt  = Mega(Watt)
	GigaWatt  = Giga(Watt)
	TeraWatt  = Tera(Watt)
	PetaWatt  = Peta(Watt)
	ExaWatt   = Exa(Watt)
	ZettaWatt = Zetta(Watt)
	YottaWatt = Yotta(Watt)

	VoltAmpere     = newUnit("volt-ampere", "V⋅A", Power, SI)
	KiloVoltAmpere = Kilo(VoltAmpere)
	MegaVoltAmpere = Mega(VoltAmpere)

	VoltAmpereReactive     = newUnit("volt-ampere reactive", "var", Power, SI)
	KiloVoltAmpereReactive = Kilo(VoltAmpereReactive)
	MegaVoltAmpereReactive = Mega(VoltAmpereReactive)
)
View Source
var (
	Pressure = Quantity("pressure")

	// SI unit metric
	Pascal      = newUnit("pascal", "Pa", Pressure, SI)
	ExaPascal   = Exa(Pascal)
	PetaPascal  = Peta(Pascal)
	TeraPascal  = Tera(Pascal)
	GigaPascal  = Giga(Pascal)
	MegaPascal  = Mega(Pascal)
	KiloPascal  = Kilo(Pascal)
	HectoPascal = Hecto(Pascal)
	DecaPascal  = Deca(Pascal)
	DeciPascal  = Deci(Pascal)
	CentiPascal = Centi(Pascal)
	MilliPascal = Milli(Pascal)
	MicroPascal = Micro(Pascal)
	NanoPascal  = Nano(Pascal)
	PicoPascal  = Pico(Pascal)
	FemtoPascal = Femto(Pascal)
	AttoPascal  = Atto(Pascal)

	// Other
	At       = newUnit("technical atmosphere", "at", Pressure, BI)
	Atm      = newUnit("standard atmosphere", "atm", Pressure, BI)
	Bar      = newUnit("bar", "bar", Pressure, BI)
	CentiBar = Centi(Bar, BI)
	MilliBar = Milli(Bar, BI)
	MicroBar = Micro(Bar, BI)
	Barye    = newUnit("barye", "Ba", Pressure, BI)
	InH2O    = newUnit(
		"inch of Water Column", "inH2O", Pressure, BI, Plural("inches of Water Column"),
	)
	InHg = newUnit("inch of Mercury", "inHg", Pressure, BI, Plural("inches of Mercury"))
	MH2O = newUnit(
		"meter of Water Column", "mmH2O", Pressure, BI,
		Plural("meters of Water Column"),
	)
	MilliMH2O     = Milli(MH2O, BI, Plural("millimeters of Water Column"))
	CentiMH2O     = Centi(MH2O, BI, Plural("centimeters of Water Column"))
	MHg           = newUnit("meter of Mercury", "mmHg", Pressure, BI, Plural("meters of Mercury"))
	MilliMHg      = Milli(MHg, BI, Plural("millimeters of Mercury"))
	CentiMHg      = Centi(MHg, BI, Plural("centimeters of Mercury"))
	NewtonSqm     = newUnit("newton per square meter", "N/m²", Pressure, BI)
	KiloNewtonSqm = Kilo(NewtonSqm)
	Psi           = newUnit("pound-force per square inch", "psi", Pressure, BI)
	Torr          = newUnit("torr", "Torr", Pressure, BI)
)
View Source
var (
	// Slope is a unit option for slope units, also known as gradient.
	Slope = Quantity("slope")

	// SlopeValue m = rise (delta h) / run (distance) = y/x = tan(alpha)
	// In the case of a vertical line, the slope is infinite.
	// In the case of a horizontal line, the slope is zero.
	SlopeValue = newUnit("slope value", "", Slope, Plural(PluralNone))
	// SlopeRatio is a ratio of one part rise to so many parts run (e.g. 1:10). == SlopeInverseValue
	SlopeRatio = newUnit("slope ratio", "", Slope, Plural(PluralNone))
	// SlopeInverseRatio is a ratio of many parts run to one part rise (e.g. 10:1).
	SlopeInverseRatio = newUnit("inverse slope ratio", "", Slope, Plural(PluralNone))
	// SlopeDegree is the angle of inclination in degrees (e.g. 45°).
	SlopeDegree = newUnit("slope degree", "", Slope, Plural(PluralNone))
	// SlopePercent 100 * m = 100 * (rise/run) = 100 * tan(α)
	SlopePercent = newUnit("slope percent", "", Slope, Plural(PluralNone))
	// SlopePermille 1000 * m = 1000 * (rise/run) = 1000 * tan(α)
	SlopePermille = newUnit("slope permille", "", Slope, Plural(PluralNone))
)
View Source
var (
	Temperature = Quantity("temperature")

	Celsius    = newUnit("celsius", "°C", Temperature, Plural(PluralNone), SI)
	Fahrenheit = newUnit("fahrenheit", "°F", Temperature, Plural(PluralNone), US)
	Kelvin     = newUnit("kelvin", "°K", Temperature, Plural(PluralNone), SI)
	Rankine    = newUnit("rankine", "°R", Temperature, Plural(PluralNone), US)
)
View Source
var (
	ThermalInsulance = Quantity("thermal insulance")

	KelvinSquareMeterPerWatt = newUnit(
		"kelvin square-metre per watt", "K·m²/W", ThermalInsulance, SI,
		Aliases("R-value"), Symbols("K*m2/W", "°C⋅m²/W", "°C*m2/W", "m2.K.W-1", "m²·K/W", "m2*K/W"),
	)

	DegreeFahrenheitHourSquareFootPerBtu = newUnit(
		"degree Fahrenheit hour square foot per British thermal unitIT", "°F⋅hr⋅ft²/Btu",
		ThermalInsulance, BI,
		Aliases(
			"degree Fahrenheit hour square foot per British thermal unit",
			"°F · h · ft2/BtuIT", "°F*hr*ft2/Btu", "°F⋅ft²⋅h/BTU", "°F⋅ft2⋅h/BTU", "°F*ft2*h/BTU",
		),
	)
)
View Source
var (
	Time = Quantity("time")

	Second      = newUnit("second", "s", Time, SI)
	ExaSecond   = Exa(Second)
	PetaSecond  = Peta(Second)
	TeraSecond  = Tera(Second)
	GigaSecond  = Giga(Second)
	MegaSecond  = Mega(Second)
	KiloSecond  = Kilo(Second)
	HectoSecond = Hecto(Second)
	DecaSecond  = Deca(Second)
	DeciSecond  = Deci(Second)
	CentiSecond = Centi(Second)
	MilliSecond = Milli(Second)
	MicroSecond = Micro(Second)
	NanoSecond  = Nano(Second)
	PicoSecond  = Pico(Second)
	FemtoSecond = Femto(Second)
	AttoSecond  = Atto(Second)

	Minute = newUnit("minute", "min", Time)
	Hour   = newUnit("hour", "hr", Time)
	Day    = newUnit("day", "d", Time)
	Month  = newUnit("month", "", Time)
	Year   = newUnit("year", "yr", Time)

	Decade     = newUnit("decade", "", Time)
	Century    = newUnit("century", "", Time)
	Millennium = newUnit("millennium", "", Time)

	// more esoteric time units
	PlanckTime = newUnit("planck time", "𝑡ₚ", Time)
	Fortnight  = newUnit("fortnight", "", Time)
	Score      = newUnit("score", "", Time)
)
View Source
var (

	// SI is the International System of Units
	SI = System(SiSystem)
	// BI is the British Imperial system of units
	BI = System(BiSystem)
	// US is the United States customary system of units
	US = System(UsSystem)
	// IEC is the International Electrotechnical Commission system of units
	IEC = System(IecSystem)
	// CGS is the centimeter-gram-second system of units
	CGS = System(CgsSystem)
	// MKpS is the MKpS system of units (from French mètre–kilogramme-poids–seconde)
	MKpS = System(MKpSSystem)
)
View Source
var (
	Voltage = Quantity("voltage")

	// metric
	Volt      = newUnit("volt", "V", Voltage, SI)
	YottaVolt = Yotta(Volt)
	ZettaVolt = Zetta(Volt)
	ExaVolt   = Exa(Volt)
	PetaVolt  = Peta(Volt)
	TeraVolt  = Tera(Volt)
	GigaVolt  = Giga(Volt)
	MegaVolt  = Mega(Volt)
	KiloVolt  = Kilo(Volt)
	HectoVolt = Hecto(Volt)
	DecaVolt  = Deca(Volt)
	DeciVolt  = Deci(Volt)
	CentiVolt = Centi(Volt)
	MilliVolt = Milli(Volt)
	MicroVolt = Micro(Volt)
	NanoVolt  = Nano(Volt)
	PicoVolt  = Pico(Volt)
)
View Source
var (
	VolumeFlowRate = Quantity("volume flow rate")

	CubicMeterPerSecond = newUnit(
		"cubic meter per second", "m³/s", VolumeFlowRate, SI,
		Aliases("cubic metre per second"), Symbols("m3/s", "m3s-1"),
	)
	CubicMeterPerMinute = newUnit(
		"cubic meter per minute", "m³/min", VolumeFlowRate, SI,
		Aliases("cubic metre per minute"), Symbols("m3/min", "m3m-1"),
	)
	CubicMeterPerHour = newUnit(
		"cubic meter per hour", "m³/h", VolumeFlowRate, SI,
		Aliases("cubic metre per hour"), Symbols("m3/h", "m3h-1"),
	)
	CubicMeterPerDay = newUnit(
		"cubic meter per day", "m³/d", VolumeFlowRate, SI,
		Aliases("cubic metre per day"), Symbols("m3/d", "m3d-1"),
	)
	CubicDecimeterPerSecond = newUnit(
		"cubic decimeter per second", "dm³/s", VolumeFlowRate, SI,
		Aliases("cubic decimetre per second"), Symbols("dm3/s", "dm3s-1"),
	)
	CubicDecimeterPerMinute = newUnit(
		"cubic decimeter per minute", "dm³/min", VolumeFlowRate, SI,
		Aliases("cubic decimetre per minute"), Symbols("dm3/min", "dm3m-1"),
	)
	CubicDecimeterPerHour = newUnit(
		"cubic decimeter per hour", "dm³/h", VolumeFlowRate, SI,
		Aliases("cubic decimetre per hour"), Symbols("dm3/h", "dm3h-1"),
	)
	CubicDecimeterPerDay = newUnit(
		"cubic decimeter per day", "dm³/d", VolumeFlowRate, SI,
		Aliases("cubic decimetre per day"), Symbols("dm3/d", "dm3d-1"),
	)

	CubicCentimeterPerSecond = newUnit(
		"cubic centimeter per second", "cm³/s", VolumeFlowRate, SI,
		Aliases("cubic centimetre per second"), Symbols("cm3/s", "cm3s-1"),
	)
	CubicCentimeterPerMinute = newUnit(
		"cubic centimeter per minute", "cm³/min", VolumeFlowRate, SI,
		Aliases("cubic centimetre per minute"), Symbols("cm3/min", "cm3m-1"),
	)
	CubicCentimeterPerHour = newUnit(
		"cubic centimeter per hour", "cm³/h", VolumeFlowRate, SI,
		Aliases("cubic centimetre per hour"), Symbols("cm3/h", "cm3h-1"),
	)
	CubicCentimeterPerDay = newUnit(
		"cubic centimeter per day", "cm³/d", VolumeFlowRate, SI,
		Aliases("cubic centimetre per day"), Symbols("cm3/d", "cm3d-1"),
	)

	CubicInchPerSecond = newUnit("cubic inch per second", "in³/s", VolumeFlowRate)
	CubicInchPerMinute = newUnit("cubic inch per minute", "in³/min", VolumeFlowRate)
	CubicInchPerHour   = newUnit("cubic inch per hour", "in³/h", VolumeFlowRate)
	CubicInchPerDay    = newUnit("cubic inch per day", "in³/d", VolumeFlowRate)

	CubicFootPerSecond = newUnit("cubic foot per second", "ft³/s", VolumeFlowRate)
	CubicFootPerMinute = newUnit("cubic foot per minute", "ft³/min", VolumeFlowRate)
	CubicFootPerHour   = newUnit("cubic foot per hour", "ft³/h", VolumeFlowRate)
	CubicFootPerDay    = newUnit("cubic foot per day", "ft³/d", VolumeFlowRate)

	CubicYardPerSecond = newUnit("cubic yard per second", "yd³/s", VolumeFlowRate)
	CubicYardPerMinute = newUnit("cubic yard per minute", "yd³/min", VolumeFlowRate)
	CubicYardPerHour   = newUnit("cubic yard per hour", "yd³/h", VolumeFlowRate)
	CubicYardPerDay    = newUnit("cubic yard per day", "yd³/d", VolumeFlowRate)
)
View Source
var (
	Volume = Quantity("volume")

	Liter      = newUnit("liter", "l", Volume, SI, Aliases("litre"))
	ExaLiter   = Exa(Liter)
	PetaLiter  = Peta(Liter)
	TeraLiter  = Tera(Liter)
	GigaLiter  = Giga(Liter)
	MegaLiter  = Mega(Liter)
	KiloLiter  = Kilo(Liter)
	HectoLiter = Hecto(Liter)
	DecaLiter  = Deca(Liter)
	DeciLiter  = Deci(Liter)
	CentiLiter = Centi(Liter)
	MilliLiter = Milli(Liter)
	MicroLiter = Micro(Liter)
	NanoLiter  = Nano(Liter)
	PicoLiter  = Pico(Liter)
	FemtoLiter = Femto(Liter)
	AttoLiter  = Atto(Liter)

	CubicMeter      = newUnit("cubic meter", "m³", Volume, SI)
	CubicKiloMeter  = newUnit("cubic kilometer", "km³", Volume, SI)
	CubicHectoMeter = newUnit("cubic hectometer", "hm³", Volume, SI)
	CubicDecaMeter  = newUnit("cubic decameter", "dam³", Volume, SI)
	CubicDeciMeter  = newUnit("cubic decimeter", "dm³", Volume, SI)
	CubicCentiMeter = newUnit("cubic centimeter", "cm³", Volume, SI)
	CubicMilliMeter = newUnit("cubic millimeter", "mm³", Volume, SI)

	// imperial
	Quart      = newUnit("quart", "qt", Volume, BI)
	Pint       = newUnit("pint", "pt", Volume, BI)
	Gallon     = newUnit("gallon", "gal", Volume, BI)
	FluidOunce = newUnit("fluid ounce", "fl oz", Volume, BI)
	CubicFoot  = newUnit("cubic foot", "ft³", Volume, BI)
	CubicYard  = newUnit("cubic yard", "yd³", Volume, BI)
	CubicInch  = newUnit("cubic inch", "in³", Volume, BI)
	CubicMile  = newUnit("cubic mile", "mi³", Volume, BI)
	AcreFoot   = newUnit("acre foot", "ac ft", Volume, BI)

	// US
	FluidQuart          = newUnit("fluid quart", "fl qt", Volume, US)
	FluidPint           = newUnit("fluid pint", "fl pt", Volume, US)
	FluidGallon         = newUnit("fluid gallon", "", Volume, US)
	CustomaryFluidOunce = newUnit("customary fluid ounce", "", Volume, US)
)
View Source
var DefaultFmtOptions = FmtOptions{true, false, 6}

Functions

func GetCsv

func GetCsv() []string

GetCsv returns a CSV representation of all registered Units.

func NewConversion

func NewConversion(from, to *Unit, formula string) (err error)

NewConversion registers a new conversion formula from one Unit to another

func NewConversionFromFn

func NewConversionFromFn(from, to *Unit, f ConversionFn, formula string)

NewConversionFromFn registers a new conversion formula from one Unit to another.

NOTE:

  • When using `NewConversionFromFn` directly, you must define conversions in both directions!

Example:

NewConversionFromFn(SlopeValue, SlopeDegree, slopeValueToDegree, "math.Atan(x) * 180 / math.Pi")
NewConversionFromFn(SlopeDegree, SlopeValue, slopeDegreeToValue, "math.Tan(x * math.Pi / 180)")

func NewRatioConversion

func NewRatioConversion(from, to *Unit, ratio float64)

NewRatioConversion registers a conversion formula and the _inverse_, given a ratio of from Unit in to Unit

Types

type AddResult

type AddResult struct {
	What     string           // "Aliases" or "Symbols", depending on what was added
	Unit     *Unit            // the unit to which the aliases or symbols were added
	Added    []string         // the aliases or symbols that were added
	Failures map[string]error // the aliases or symbols that failed to be added, and the reason why
	Err      error            // the overall error that occurred, if any
	Summary  string           // a summary of the result
}

AddResult is the result of adding aliases or symbols to a unit

func (*AddResult) String

func (ar *AddResult) String() string

String returns a summary of the AddResult

type Conversion

type Conversion struct {
	Fn      ConversionFn
	Formula string
	// contains filtered or unexported fields
}

func ResolveConversion

func ResolveConversion(from, to *Unit) (cpath []Conversion, err error)

ResolveConversion resolves a path of one or more Conversions between two units

func (Conversion) From

func (c Conversion) From() string

From returns the name of the unit to convert from

func (Conversion) String

func (c Conversion) String() string

String representation of conversion formula

func (Conversion) To

func (c Conversion) To() string

To returns the name of the unit to convert to

type ConversionFn

type ConversionFn func(float64) float64

type FmtOptions

type FmtOptions struct {
	Label     bool // if false, unit label/symbol will be omitted
	Short     bool // if true, use unit shortname or symbol
	Precision int  // maximum meaningful precision to truncate value
}

type Unit

type Unit struct {
	// Name is the (english) name of this unit. The name is mandatory and case-insensitive.
	Name string
	// Symbol is the (main) symbol for this unit, e.g. "m" for meters. The symbol is mandatory and case-sensitive.
	Symbol string
	// Quantity is the quantity label for which this unit belongs, e.g. "length" or "area"
	Quantity UnitQuantity
	// contains filtered or unexported fields
}

Unit represents a unit of measurement

func All

func All() []*Unit

All returns all registered Units, sorted by name and quantity

func Atto

func Atto(b *Unit, o ...UnitOption) *Unit

func Centi

func Centi(b *Unit, o ...UnitOption) *Unit

func Deca

func Deca(b *Unit, o ...UnitOption) *Unit

func Deci

func Deci(b *Unit, o ...UnitOption) *Unit

func Exa

func Exa(b *Unit, o ...UnitOption) *Unit

func Femto

func Femto(b *Unit, o ...UnitOption) *Unit

func Find

func Find(s string) (*Unit, error)

Find a Unit matching the given name, symbol or alias

func Giga

func Giga(b *Unit, o ...UnitOption) *Unit

func Hecto

func Hecto(b *Unit, o ...UnitOption) *Unit

func Kilo

func Kilo(b *Unit, o ...UnitOption) *Unit

func Mega

func Mega(b *Unit, o ...UnitOption) *Unit

func Micro

func Micro(b *Unit, o ...UnitOption) *Unit

func Milli

func Milli(b *Unit, o ...UnitOption) *Unit

func Nano

func Nano(b *Unit, o ...UnitOption) *Unit

func NewUnit

func NewUnit(name, symbol string, opts ...UnitOption) (*Unit, error)

NewUnit registers a new Unit within the package, returning the newly created Unit. Returns an error if the unit already exists. The name is mandatory and must be unique. The symbol is optional, but if provided, must be unique.

func Peta

func Peta(b *Unit, o ...UnitOption) *Unit

func Pico

func Pico(b *Unit, o ...UnitOption) *Unit

func Quecto

func Quecto(b *Unit, o ...UnitOption) *Unit

func Quetta

func Quetta(b *Unit, o ...UnitOption) *Unit

Magnitude prefix methods create and return a new Unit, while automatically registering conversions to and from the provided base Unit

func Ronna

func Ronna(b *Unit, o ...UnitOption) *Unit

func Ronto

func Ronto(b *Unit, o ...UnitOption) *Unit

func Tera

func Tera(b *Unit, o ...UnitOption) *Unit

func Yocto

func Yocto(b *Unit, o ...UnitOption) *Unit

func Yotta

func Yotta(b *Unit, o ...UnitOption) *Unit

func Zepto

func Zepto(b *Unit, o ...UnitOption) *Unit

func Zetta

func Zetta(b *Unit, o ...UnitOption) *Unit

func (*Unit) AddAliases

func (u *Unit) AddAliases(aliases ...string) *AddResult

AddAliases adds aliases that this unit may be referred to

func (*Unit) AddSymbols

func (u *Unit) AddSymbols(symbols ...string) *AddResult

AddSymbols adds symbols that this unit may be referred to

func (*Unit) Aliases

func (u *Unit) Aliases() []string

Aliases returns all aliases this unit may be referred to.

func (*Unit) ConvertTo

func (u *Unit) ConvertTo(value float64, to *Unit) (Value, error)

ConvertTo converts the provided value from this unit to the provided unit

func (*Unit) CsvLine

func (u *Unit) CsvLine() string

CsvLine returns a CSV line for this unit The line contains the following fields: Name, Symbol, PluralName, Quantity, System, Aliases, Symbols

func (*Unit) HasName

func (u *Unit) HasName(alias string) bool

HasName returns true if the provided string matches the provided Unit's Name or Aliases

func (*Unit) HasSymbol

func (u *Unit) HasSymbol(symbol string) bool

HasSymbol returns true if the provided string matches the provided Unit's Symbol or Symbols

func (*Unit) Names

func (u *Unit) Names() []string

Names returns all names and aliases this unit may be referred to. The main name is always the first in the list. Names and aliases are NOT case-sensitive!

func (*Unit) PluralName

func (u *Unit) PluralName() string

PluralName returns the plural name for this unit

func (*Unit) String

func (u *Unit) String() string

String returns the name of this unit

func (*Unit) Symbols

func (u *Unit) Symbols() []string

Symbols returns all symbols this unit may be referred to. The main symbol is always the first in the list. Symbols are case-sensitive!

func (*Unit) System

func (u *Unit) System() UnitSystem

System returns the system of units this Unit belongs to, if any

type UnitList

type UnitList []*Unit

UnitList is a slice of Units. UnitList implements sort.Interface

func (UnitList) Len

func (a UnitList) Len() int

Len returns the length of the UnitList

func (UnitList) Less

func (a UnitList) Less(i, j int) bool

Less returns whether the Unit at index i is less than the Unit at index j

func (UnitList) Swap

func (a UnitList) Swap(i, j int)

Swap swaps the Units at the given indices

type UnitOption

type UnitOption func(*Unit) *Unit

UnitOption defines an option that may be passed to newUnit

func Aliases

func Aliases(aliases ...string) UnitOption

Aliases sets the aliases for this Unit

func Plural

func Plural(s string) UnitOption

Plural sets the plural name for this unit, either PluralNone, PluralAuto, or a custom plural unit name

  • PluralNone - labels will use the unmodified unit name in a plural context
  • PluralAuto - labels for this unit will be created with a plural suffix when appropriate (default)

func Quantity

func Quantity(s UnitQuantity) UnitOption

Quantity sets a quantity label for which this Unit belongs

func Symbols

func Symbols(symbols ...string) UnitOption

Symbols sets the symbols for this Unit

func System

func System(s UnitSystem) UnitOption

System sets the system of units for which this Unit belongs

type UnitQuantity

type UnitQuantity string

UnitQuantity is a quantity label for which a unit belongs

func (UnitQuantity) String

func (q UnitQuantity) String() string

Quantity labels for which units may belong

type UnitSystem

type UnitSystem string

UnitSystem is a system of units

const (
	// SiSystem provides the internal name for International System of Units
	SiSystem UnitSystem = "metric"
	// BiSystem provides the internal name the British Imperial system of units
	BiSystem UnitSystem = "imperial"
	// UsSystem provides the internal name the United States customary system of units
	UsSystem UnitSystem = "us"
	// IecSystem provides the internal name the International Electrotechnical Commission system of units
	IecSystem UnitSystem = "iec"
	// CgsSystem provides the internal name the centimeter-gram-second system of units
	CgsSystem UnitSystem = "cgs"
	// MKpSSystem provides the internal name the MKpS system of units (from French mètre–kilogramme-poids–seconde)
	MKpSSystem UnitSystem = "MKpS"
)

func (UnitSystem) String

func (s UnitSystem) String() string

Systems of units

type Value

type Value struct {
	// contains filtered or unexported fields
}

func ConvertFloat

func ConvertFloat(x float64, from, to *Unit) (Value, error)

ConvertFloat converts a provided float from one Unit to another

func MustConvertFloat

func MustConvertFloat(x float64, from, to *Unit) Value

MustConvertFloat converts a provided float from one Unit to another, PANICKING on error

func NewValue

func NewValue(v float64, u Unit) Value

NewValue creates a new Value instance

func (Value) Convert

func (v Value) Convert(to Unit) (Value, error)

Convert converts this Value to another Unit

func (Value) Float

func (v Value) Float() float64

Float returns the float value of this Value

func (Value) Fmt

func (v Value) Fmt(opts FmtOptions) string

Fmt returns a string representation of this Value, using the provided FmtOptions

func (Value) MustConvert

func (v Value) MustConvert(to Unit) Value

MustConvert converts this Value to another Unit, PANICKING on error

func (Value) String

func (v Value) String() string

String returns a string representation of this Value

func (Value) Unit

func (v Value) Unit() Unit

Unit returns the Unit of this Value

Directories

Path Synopsis
Package numericstring provides constants with numeric strings for conversion tests
Package numericstring provides constants with numeric strings for conversion tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL