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, "oz.tr."); // ounce

UnitConverter.RegisterCustomUnit(custom);

var result = UnitConverter.ToUnitOfMeasurement("oz.tr.");

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 94 7/10/2024
2.0.1 831 11/28/2022
2.0.0 868 10/24/2022
1.5.3 885 8/21/2022
1.5.2 875 8/21/2022
1.5.1 922 4/27/2022
1.5.0 931 3/12/2022
1.4.0 884 3/12/2022
1.3.0 867 3/12/2022
1.2.2 860 3/11/2022
1.2.1 932 3/11/2022
1.2.0 923 3/11/2022
1.1.1 903 3/11/2022
1.1.0 890 3/11/2022
1.0.5 928 3/11/2022
1.0.4 902 3/11/2022