A simple library for working with units of measure in .NET.
The goal of this library is to assist developers with quick proof of concepts as well as full functioning projects which involve common units of measure.
Feedback and assistance are welcome!
Package | Release | Pre-Release | License |
---|---|---|---|
Fs.Units | |||
Fs.Units.CSharp |
GitHub Actions |
---|
- Simple Units: A basic unit of measure
[<Measure>] type inch
- Compound Units: Derived units of measure consisting of combinations of two or more units of measure
[<Measure>] type in2 = inch * inch
open Fs.Units
let valueInFeet = Inch.create 1.0 |> Inch.toFeet // float<ft>
For some compound units, implicit conversion is supported. This allows for a more natural syntax.
open Fs.Units
let thing1 = Coulomb.create 1.0 // float<ElectricCharge.C>
let thing2 = 1.<A> * 1.<s> // float<A*s>
let totalThing = area1 + area2 // float<ElectricCharge.C>
open Fs.Units
let thing1 = Liter.create 1.0 // float<L>
let thing2 = 1.<dm> * 1.<dm> * 1.<dm> // float<dm * dm * dm>
let totalThing = area1 + area2 // float<L>
Some helper functions are provided to prevent boilerplate code for common math operations such as min, max, abs, etc.
open Fs.Units
open Fs.Units.Helpers
let value1 = Foot.create 1.0 // float<ft>
let value2 = Foot.create 2.0 // float<ft>
let maxValue = max value1 value2 // float<ft>
using Fs.Units.CSharp;
var valueInFeet = 1d.InchToFeet(); // double
- Inch
- Foot
- Yard
- Mile
- Millimeter
- Centimeter
- Decimeter
- Meter
- Kilometer
- NauticalMile
- Chain
- Furlong
- League
- Hand
- Rod
- Nanosecond
- Microsecond
- Millisecond
- Second
- Minute
- Hour
- Day
- Week
- Fortnight
- Month
- Year
- Decade
- Century
- Millenium
- Eon
- Milligram
- Gram
- Kilogram
- Pound mass
- Kelvin
- Celsius
- Fahrenheit
- Rankine
- Degree
- Radian
- Gradian
- Revolution
- Arcminute
- Arcsecond
- Bit
- Kilobit
- Megabit
- Gigabit
- Terabit
- Petabit
- Byte
- Kilobyte
- Megabyte
- Gigabyte
- Terabyte
- Petabyte
- Hertz
- Kilohertz
- Megahertz
- Gigahertz
- Footcandle
- Lux
- Phot
- Nox
- Microampere
- Milliampere
- Ampere
- Biot
- SquareInch
- SquareFoot
- SquareCentimeter
- SquareMeter
- CubicInch
- CubicFoot
- CubicCentimeter
- CubicMeter
- Liter
- Gallon
- MilesPerGallon
- KilometersPerLiter
- QuarticInch
- QuarticCentimeter
- FeetPerSecond
- MetersPerSecond
- MilesPerHour
- KilometersPerHour
- Newton
- PoundForce
- Dyne
- Kip
- Baud
- BitsPerSecond
- KilobitsPerSecond
- MegabitsPerSecond
- GigabitsPerSecond
- TerabitsPerSecond
- PetabitsPerSecond
- BytesPerSecond
- KilobytesPerSecond
- MegabytesPerSecond
- GigabytesPerSecond
- TerabytesPerSecond
- PetabytesPerSecond
- KilogramsPerCubicMeter
- GramsPerCubicCentimeter
- PoundMassPerCubicFoot
- PoundMassPerCubicInch
- Pascal
- PoundsPerSquareInch
- Watt
- KiloWatt
- ImperialHorsepower
- TonOfRefrigeration
- Joules
- KiloJoules
- BritishThermalUnits
- calories
- Quads
- Q
- Coulomb
- AmpereHour
- AmpereSecond
- Microvolts
- Millivolts
- Volts
- Kilovolts
- Megavolts
- Farads
- MicroHenrys
- MilliHenrys
- Henrys