DoenaSoft.UnitsOfMeasurement 2.0.2

dotnet add package DoenaSoft.UnitsOfMeasurement --version 2.0.2                
NuGet\Install-Package DoenaSoft.UnitsOfMeasurement -Version 2.0.2                
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="DoenaSoft.UnitsOfMeasurement" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DoenaSoft.UnitsOfMeasurement --version 2.0.2                
#r "nuget: DoenaSoft.UnitsOfMeasurement, 2.0.2"                
#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 DoenaSoft.UnitsOfMeasurement as a Cake Addin
#addin nuget:?package=DoenaSoft.UnitsOfMeasurement&version=2.0.2

// Install DoenaSoft.UnitsOfMeasurement as a Cake Tool
#tool nuget:?package=DoenaSoft.UnitsOfMeasurement&version=2.0.2                

This package allows the conversion of common SI and American units within the same category (area, energy, length, temperature, time, volume, weight/mass)

All units can be accessed by type name (e.g. Meter) or serializable / SI value (e.g. "m");

Sample conversion from Kilogram to pound:

var lb = new Value<Pound>(1);

var kg = ValueConverter.Convert<Kilogram>(lb).Round(9);

Assert.AreEqual(0.45359237, kg.Scalar);

kg = new Value<Kilogram>(1);

lb = ValueConverter.Convert<Pound>(kg).Round(9);

Assert.AreEqual(2.204622622, lb.Scalar);

It also allows the registration of custom units (i.e not pre-defined in this assembly) with a conversion factor to the category's base unit.

var custom = new CustomWeight(0.0311034768, ""); // ounce


var result = UnitConverter.ToUnitOfMeasurement("");

It also alows the creation of fractional units such as meters per second

var mps = UnitConverter.ToUnitOfMeasurement("m/s");

You can also add values from the same unit category to each other without converting the units first:

var source = new Value<FractionUnit<Meter, Second>>(30);

var target = source.Add(new Value<FractionUnit<Mile, Hour>>(15));

Or calculate Superman's height in meters:

var sourceFeet = new Value<Foot>(6).Add(new Value(4, "inc")); // 6'4"

var targetMeter = ValueConverter.Convert<Meter>(sourceFeet).Round(2); // 1.93m

You can also convert between volume and weight units with a given density.

const double DensityOfHelium = 0.1785; // kg/l

var source = new Value(5, UnitConverter.ToUnitOfMeasurement("dm3"));

var target = ValueConverter.Convert(source, new Kilogram(), new DensityValue<Density<Kilogram, Liter>>(DensityOfHelium)); // 0.8925kg

You can even convert values with fractional units where the unit categories are inverted, such as liter per 100 km (volume/length) to gasmileage (length/volume)

const double LitersPerKm = 5.9 / 100;

var source = new Value<FractionUnit<Liter, Kilometer>>(LitersPerKm);

var target = ValueConverter.Convert(source, new FractionUnit<Mile, USLiquidGallon>()).Round(5); // 39.86688 miles per gallon

More examples can be found in the unit tests for the project

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  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.2 52 7/10/2024
2.0.1 798 11/28/2022
2.0.0 845 10/24/2022
1.5.3 863 8/21/2022
1.5.2 851 8/21/2022
1.5.1 894 4/27/2022
1.5.0 907 3/12/2022
1.4.0 863 3/12/2022
1.3.0 847 3/12/2022
1.2.2 833 3/11/2022
1.2.1 890 3/11/2022
1.2.0 894 3/11/2022
1.1.1 867 3/11/2022
1.1.0 860 3/11/2022
1.0.5 897 3/11/2022
1.0.4 873 3/11/2022