Net-MeasurementUnits 1.1.1

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

// Install Net-MeasurementUnits as a Cake Tool
#tool nuget:?package=Net-MeasurementUnits&version=1.1.1

MeasurementUnits

A .net library to convert common units of measure including Mass, Volume, Length and Temperature.

Please note that at this time there is no way to allow conversions between the measurement types (ie. Cannot convert a Mass Unit to Length)

Uses

The following example converts 3.875 kilometers to miles by creating a mile object then calling the FromLengthUnit() method that is a part of each length unit class

var _km = new km(3.875);

var _mi = mi.FromLengthUnit(_km);

Console.Out.WriteLine($"3.875 kilometers converted to miles equals {_mi.Value}");

You can also convert a value directly without instantiating the starting value type object by calling the ConvertFrom() method. It takes a LengthUnits enum value, and the starting value as parameters:

var _mi = mi.ConvertFrom(LengthUnits.km, 3.875);

Console.Out.WriteLine($"3.875 kilometers converted to miles equals {_mi.Value}");

The following tables show the available unit types

Length Units

Class Name Unit Name
cm centimeters
dm decimeters
m meters
dam dekameters
hm hectometers
km kilometers
thou thou
_in inches
ft feet
yd yards
mi miles
fur furlongs

Length Units can now be determined by providing GeoCoordinates (Latitude and Longitude). Simply provide the lat1, lon1, lat2, lon2, and desired result unit type and the distance will be returned as a double.

var distanceInFeet = LengthConverter.GetLengthFromGPSPoints(41.731363, -111.834969, 41.733271, -111.834902, LengthUnits.ft);

Mass Units

Class Name Unit Name
mg milligrams
cg centigrams
dg decigrams
g grams
dag dekagrams
hg hectograms
kg kilograms
oz ounces
lb pounds
t_us ton (US)
t_met tonne (metric)
t_imp ton (imperial)

Volume Units

Class Name Unit Name
ml milliliters
cl centiliters
dl deciliters
L liters
daL dekaliters
hL hectoliters
kL kiloliters
fl_oz_us fluid ounces (US)
fl_oz_imp fluid ounces (imperial)
pt_us pints (US)
pt_imp pints (imperial)
qt_us quarts (US)
qt_imp quarts (imperial)
gal_us gallons (US)
gal_imp gallons (imperial)

Temperature Units

Class Name Unit Name
K Kelvin
C Celcius
F Fahrenheit

Since temperatures don't convert the same way distances do (ie. temperatures aren't mere ratios of each other like distances are and 0 is not always 0 across the board), there isn't a FromTempUnit() method. Instead use the ConvertFrom() method that takes a start value and a start unit enum. Or use the TempConverter.GetTempConverted static method.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

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
1.1.1 456 2/21/2022
1.1.0 402 2/21/2022
1.0.0 465 11/15/2021