Fs.Units.CSharp 2.0.0

dotnet add package Fs.Units.CSharp --version 2.0.0                
NuGet\Install-Package Fs.Units.CSharp -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fs.Units.CSharp" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fs.Units.CSharp --version 2.0.0                
#r "nuget: Fs.Units.CSharp, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fs.Units.CSharp as a Cake Addin
#addin nuget:?package=Fs.Units.CSharp&version=2.0.0

// Install Fs.Units.CSharp as a Cake Tool
#tool nuget:?package=Fs.Units.CSharp&version=2.0.0                

Fs.Units

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!

NuGet

Package Release Pre-Release License
Fs.Units NuGet version (Fs.Units) NuGet GitHub license
Fs.Units.CSharp NuGet version (Fs.Units.CSharp) NuGet GitHub license

Builds

GitHub Actions
GitHub Actions
Build History

Table of Contents

Unit Types

  • 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

Examples

F#

Explicit Conversion Example
open Fs.Units

let valueInFeet = Inch.create 1.0 |> Inch.toFeet // float<ft>
Implicit Conversion Example

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>
Helper Functions

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>

C#

Example
using Fs.Units.CSharp;

var valueInFeet = 1d.InchToFeet(); // double

Supported Unit Categories

Simple

Length
  • Inch
  • Foot
  • Yard
  • Mile
  • Millimeter
  • Centimeter
  • Decimeter
  • Meter
  • Kilometer
  • NauticalMile
  • Chain
  • Furlong
  • League
  • Hand
  • Rod
Time
  • Nanosecond
  • Microsecond
  • Millisecond
  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Fortnight
  • Month
  • Year
  • Decade
  • Century
  • Millenium
  • Eon
Mass
  • Milligram
  • Gram
  • Kilogram
  • Pound mass
Temperature
  • Kelvin
  • Celsius
  • Fahrenheit
  • Rankine
Angle
  • Degree
  • Radian
  • Gradian
  • Revolution
  • Arcminute
  • Arcsecond
DataStorage
  • Bit
  • Kilobit
  • Megabit
  • Gigabit
  • Terabit
  • Petabit
  • Byte
  • Kilobyte
  • Megabyte
  • Gigabyte
  • Terabyte
  • Petabyte
Frequency
  • Hertz
  • Kilohertz
  • Megahertz
  • Gigahertz
Illuminance
  • Footcandle
  • Lux
  • Phot
  • Nox
Current
  • Microampere
  • Milliampere
  • Ampere
  • Biot

Compound

Area
  • SquareInch
  • SquareFoot
  • SquareCentimeter
  • SquareMeter
Volume
  • CubicInch
  • CubicFoot
  • CubicCentimeter
  • CubicMeter
  • Liter
  • Gallon
FuelEconomy
  • MilesPerGallon
  • KilometersPerLiter
Inertia
  • QuarticInch
  • QuarticCentimeter
Speed
  • FeetPerSecond
  • MetersPerSecond
  • MilesPerHour
  • KilometersPerHour
Force
  • Newton
  • PoundForce
  • Dyne
  • Kip
DataTransferRate
  • Baud
  • BitsPerSecond
  • KilobitsPerSecond
  • MegabitsPerSecond
  • GigabitsPerSecond
  • TerabitsPerSecond
  • PetabitsPerSecond
  • BytesPerSecond
  • KilobytesPerSecond
  • MegabytesPerSecond
  • GigabytesPerSecond
  • TerabytesPerSecond
  • PetabytesPerSecond
Density
  • KilogramsPerCubicMeter
  • GramsPerCubicCentimeter
  • PoundMassPerCubicFoot
  • PoundMassPerCubicInch
Pressure
  • Pascal
  • PoundsPerSquareInch
Power
  • Watt
  • KiloWatt
  • ImperialHorsepower
  • TonOfRefrigeration
Energy
  • Joules
  • KiloJoules
  • BritishThermalUnits
  • calories
  • Quads
  • Q
ElectricCharge
  • Coulomb
  • AmpereHour
  • AmpereSecond
ElectromotiveForce
  • Microvolts
  • Millivolts
  • Volts
  • Kilovolts
  • Megavolts
Capacitance
  • Farads
Inductance
  • MicroHenrys
  • MilliHenrys
  • Henrys
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 233 12/7/2023
1.0.0 215 11/14/2022

- Convert library to .NET Standard 2.0
- Namespace reorganization for better ergonomics (Only need to `open Fs.Units` now)
- Project folder restructure
- Add build project
- Add dotnet tooling
- Add .editorconfig
- Add Decimeter to Length modules
- Add Liter to Volume modules
- Add Gallon to Volume modules
- Moved FuelEconomy to compound folder and update types to include simple unit components