Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MadsKirkFoged/EngineeringUnits

Repository files navigation

EngineeringUnits

EngineeringUnits is a .NET units-of-measure library built for engineering equations: you can write formulas naturally, keep units attached to values, and get upfront errors when you mess up dimensional analysis.

  • No more having your units in doubles with comments above it explaining what type of unit it is.
  • No more magic "* 1000" constants floating around in your equations.
  • No more rechecking "Did I have all my values converted correctly?"
  • No more side notes checking if the units of an equation match

The only place you care about unit types are at the edge of your code.

//Value enters from outside your code
double Inputfield = 21;

//Transfers into an EngineeringUnits unit
Temperature TIn = Temperature.FromDegreesCelsius(Inputfield); //21 degC

//Math
Temperature TOut = TIn - 10.Kelvin; //11 degC

//Converts to DegreeFahrenheit
Temperature USCustomer = TOut.ToUnit(TemperatureUnit.DegreeFahrenheit); //51.8 degF

//Display it
string Output2 = USCustomer.ToString("S2"); // Output: 52 degF

Why EngineeringUnits?

  • You can do arithmetic between any unit and keep the result unit-safe.
  • Unit-safe math: multiply/divide/add/subtract quantities and let us handle the resulting unit.
  • Compile time unit validation: Your equations are checked for correct units while you write it.
  • High precision conversions
  • Aliases: multiple names can represent the same dimension (e.g., SpecificEnergy vs Enthalpy).
  • helpers: Min/Max/Average/mean, Clamp, abs and built-in physical constants.

Install as nuget package

dotnet add package EngineeringUnits

Quick start

If you already use UnitsNet, switching is usually just changing the using:

// UnitsNet:
// using UnitsNet;
// using UnitsNet.Units;

using EngineeringUnits;
using EngineeringUnits.Units;

Unit-safe engineering math

SpecificEntropy p1 = 1.JoulePerKilogramKelvin;
MassFlow m1 = 1.KilogramPerSecond;
Temperature t2 = 10.DegreeCelsius;
Temperature t1 = 5.DegreeCelsius;

Power q = m1 * p1 * (t2 - t1); // 5 W

Conversion (round-trip safe)

Length oneMeter = 1.Meter;

Length inFoot = oneMeter.ToUnit(LengthUnit.Foot);
Length backToMeter = inFoot.ToUnit(LengthUnit.Meter);

bool roundTripOk = oneMeter == backToMeter; // true

Catch unit mistakes early

Mass mass = 10.Kilogram;
Volume volume = 4.CubicMeter;

Density d1 = mass / volume; // OK: kg/m3

// Compile-time error
Density d2 = volume / mass; // shows a red line. Wouldn't let you run the code before it is fixed!

Very large collection of units

Expand to see list of Units included Acceleration:[m/s2], [km/s2], [m/s2], [dm/s2], [cm/s2], [um/s2], [mm/s2], [nm/s2], [in/s2], [ft/s2], [kn/s], [kn/min], [kn/h], [g], [mg],
AreaDensity:[kg/m2], [kg/m2],
AreaMomentOfInertia:[m4], [m4], [cm4], [dm4], [mm4], [in4], [ft4],
Area:[ac], [ha], [cm2], [dm2], [km2], [m2], [um2], [m2], [mm2], [nm2], [in2], [ft2], [yd2], [mi2], [nmi2], [ch2],
AreaCost:[$/m2], [$/m2], [M$/m2], [?/m2],
BitRate:[], [B/s], [bit/s], [Kibit/s], [Mibit/s], [Gibit/s], [Tibit/s], [Pibit/s], [Eibit/s], [KiB/s], [MiB/s], [GiB/s], [TiB/s], [PiB/s], [EiB/s], [kB/s], [MB/s], [GB/s], [TB/s], [PB/s], [EB/s], [kbit/s], [Mbit/s], [Gbit/s], [Tbit/s], [Pbit/s], [Ebit/s],
BrakeSpecificFuelConsumption:[kg/J], [kg/J], [g/kWh], [lb/hph],
Capacitance:[F], [F], [kF], [MF], [uF], [mF], [nF], [pF],
CoefficientOfThermalExpansion:[/K], [K?1], [/degF], [/degC],
Density:[kg/m3], [cg/dl], [cg/l], [cg/ml], [dg/dl], [dg/l], [dg/ml], [dg/ul], [g/cm3], [g/m3], [g/mm3], [g/dl], [g/l], [g/ml], [g/ul], [kg/cm3], [kg/m3], [kg/mm3], [kg/l], [kip/ft3], [kip/in3], [ug/m3], [ug/dl], [ug/l], [ug/ml], [ug/ul], [mg/m3], [mg/dl], [mg/l], [mg/ml], [mg/ul], [ng/dl], [ng/l], [ng/ml], [ng/ul], [pg/dl], [pg/l], [pg/ml], [pg/ul], [lb/ft3], [lb/in3], [ppg (imp.)], [ppg (U.S.)], [slug/ft3], [t/cm3], [t/m3], [t/mm3],
DynamicViscosity:[Pa*s], [Pa*s], [uPa*s], [mPa*s], [lb/ft*s], [P], [cP], [N*s/m2], [lbf*s/ft2], [lbf*s/in2], [reyn],
ElectricChargeDensity:[C/m3], [C/m3],
ElectricCharge:[C], [C], [A-h], [kA-h], [MA-h], [mA-h],
ElectricConductivity:[S/m], [S/m], [S/in], [S/ft],
ElectricCurrentDensity:[A/m2], [A/m2], [A/in2], [A/ft2],
ElectricCurrentGradient:[A/s], [A/s], [A/us], [A/ms], [A/ns],
ElectricField:[V/m], [V/m],
ElectricInductance:[H], [H], [uH], [mH], [nH],
ElectricPotentialChangeRate:[V/s], [V/s], [V/min], [V/us], [V/h], [mV/s], [mV/min], [mV/us], [mV/h], [uV/s], [uV/min], [uV/us], [uV/h], [MV/s], [MV/min], [MV/us], [MV/h], [kV/s], [kV/min], [kV/us], [kV/h],
ElectricPotential:[V], [V], [kV], [MV], [GV], [uV], [mV],
MolarMass:[kg/mol], [kg/mol], [cg/mol], [dag/mol], [dg/mol], [g/mol], [hg/mol], [kip/mol], [Mlb/mol], [ug/mol], [mg/mol], [ng/mol], [lb/mol],
ElectricResistance:[O], [O], [GO], [kO], [MO], [uO], [mO],
ElectricResistivity:[O*m], [O*m], [O*cm], [kO*cm], [MO*cm], [uO*cm], [mO*cm], [nO*cm], [pO*cm], [kO*m], [MO*m], [uO*m], [mO*m], [nO*m], [pO*m],
ElectricSurfaceChargeDensity:[C/m2], [C/m2], [C/cm2], [C/in2],
Energy:[J], [mJ], [J], [kJ], [MJ], [GJ], [TJ], [BTU], [kBTU], [MBTU], [GBTU], [eV], [keV], [MeV], [GeV], [TeV], [cal], [kcal], [Mcal], [Wday], [kWday], [MWday], [GWday], [TWday], [Wh], [kWh], [MWh], [GWh], [TWh], [ft*lb], [Dth (E.C.)], [Dth (imp.)], [Dth (U.S.)], [th (E.C.)], [th (imp.)], [th (U.S.)], [erg], [hp*h],
EnergyCost:[$/J], [$/J], [$/kJ], [$/MJ], [$/GJ], [$/kWh], [$/MWh], [M$/J], [M$/kJ], [M$/MJ], [M$/GJ], [M$/kWh], [M$/MWh],
Entropy:[J/K], [J/K], [cal/K], [J/K], [kcal/K], [kJ/K], [kJ/K], [MJ/K],
ForceChangeRate:[N/s], [N/s], [N/min], [lbf/s], [lbf/min], [klbf/s], [klbf/min], [nN/s], [mN/s], [uN/s], [cN/s], [daN/s], [dN/s], [kN/s], [daN/min], [kN/min],
ForcePerLength:[N/m], [N/m], [N/cm], [N/mm], [kgf/cm], [kgf/m], [kgf/mm], [kN/cm], [kN/m], [kN/mm], [kipf/ft], [kipf/in], [MN/cm], [MN/m], [MN/mm], [uN/cm], [uN/m], [uN/mm], [mN/cm], [mN/m], [mN/mm], [lbf/ft], [lbf/in], [lbf/yd], [tf/cm], [tf/m], [tf/mm], [nN/cm], [nN/m], [nN/mm], [cN/cm], [cN/m], [cN/mm], [daN/cm], [daN/m], [daN/mm], [dN/cm], [dN/m], [dN/mm],
Force:[N], [N], [uN], [mN], [daN], [kN], [MN], [dyn], [tf], [tf (short)], [lbf], [kgf], [ozf], [kp], [kipf], [Mlbf], [pdl],
Frequency:[Hz], [Hz], [kHz], [MHz], [GHz], [THz], [s?1], [bpm], [RPM], [RPM], [cph], [cpm], [rad/s],
FuelEfficiency:[m/m3], [km/l], [mpg (imp.)], [mpg (U.S.)],
HeatFlux:[W/m2], [W/m2], [W/in2], [W/ft2], [BTU/h*ft2], [BTU/min*ft2], [BTU/s*ft2], [BTU/s*in2], [cal/s*cm2], [kcal/h*m2], [kcal/s*cm2], [kW/m2], [uW/m2], [mW/m2], [nW/m2], [cW/m2], [dW/m2], [lbf/(ft*s)], [lb/s3],
HeatTransferCoefficient:[W/m2K], [W/m2K], [W/m2degC], [Btu/ft2hrdegF],
Illuminance:[lx], [lx], [klx], [Mlx], [mlx],
Information:[], [B], [b], [Kib], [Mib], [Gib], [Tib], [Pib], [Eib], [KiB], [MiB], [GiB], [TiB], [PiB], [EiB], [kB], [MB], [GB], [TB], [PB], [EB], [kb], [Mb], [Gb], [Tb], [Pb], [Eb],
Irradiance:[W/m2], [W/m2], [W/cm2], [kW/cm2], [MW/cm2], [uW/cm2], [mW/cm2], [nW/cm2], [pW/cm2], [kW/m2], [MW/m2], [uW/m2], [mW/m2], [nW/m2], [pW/m2],
Irradiation:[J/m2], [J/m2], [J/cm2], [J/mm2], [kJ/m2], [kWh/m2], [mJ/cm2], [Wh/m2],
KinematicViscosity:[m2/s], [m2/s], [St], [cSt], [dSt], [kSt], [uSt], [mSt], [nSt],
LapseRate:[K/m], [?degC/km],
LengthCost:[$/m], [$/m], [?/m],
LinearDensity:[kg/m], [kg/m], [g/cm], [g/m], [g/mm], [kg/cm], [kg/mm], [ug/cm], [ug/m], [ug/mm], [mg/cm], [mg/m], [mg/mm], [lb/ft], [lb/in],
LinearPowerDensity:[W/m], [W/m], [W/mm], [W/in], [W/ft], [W/cm], [mW/mm], [mW/m], [mW/in], [mW/ft], [mW/cm], [MW/mm], [MW/m], [MW/in], [MW/ft], [MW/cm], [kW/mm], [kW/m], [kW/in], [kW/ft], [kW/cm], [GW/mm], [GW/m], [GW/in], [GW/ft], [GW/cm],
LuminousFlux:[Empty], [lm],
MagneticField:[T], [T], [G], [mG], [uT], [mT], [nT],
MagneticFlux:[Wb], [Wb],
Magnetization:[A/m], [A/m],
MassCost:[$/kg], [?/kg], [$/kg], [$/t], [M$/t],
MassFlow:[cg/day], [cg/s], [dag/day], [dag/s], [dg/day], [dg/s], [g/day], [g/h], [g/s], [Mg/day], [ug/s], [ug/day], [mg/s], [mg/day], [ng/s], [ng/day], [hg/day], [hg/s], [kg/s], [kg/s], [kg/min], [kg/h], [kg/day], [lb/s], [lb/min], [lb/h], [lb/day], [Mlb/day], [Mlb/h], [Mlb/min], [Mlb/s], [short tn/h], [t/day], [t/h],
MassFlux:[kg/sm2], [kg/sm2], [g/hcm2], [g/hm2], [g/hmm2], [g/scm2], [g/sm2], [g/smm2], [kg/hcm2], [kg/hm2], [kg/hmm2], [kg/scm2], [kg/smm2],
MassMomentOfInertia:[kgm2], [kgm2], [gcm2], [gdm2], [gm2], [gmm2], [kgcm2], [kgdm2], [kgmm2], [ktcm2], [ktdm2], [ktm2], [ktmm2], [Mtcm2], [Mtdm2], [Mtm2], [Mtmm2], [mgcm2], [mgdm2], [mgm2], [mgmm2], [lbft2], [lbin2], [slugft2], [slugin2], [tcm2], [tdm2], [tm2], [tmm2],
MolarEnergy:[J/mol], [J/mol], [kJ/mol], [MJ/mol],
MolarEntropy:[J/(mol*K)], [J/(mol*K)], [kJ/(mol*K)], [MJ/(mol*K)],
Molarity:[mol/m3], [mol/m3], [mol/l], [nmol/l], [pmol/l], [cmol/l], [dmol/l], [umol/l], [mmol/l],
Permeability:[H/m], [H/m],
Permittivity:[F/m], [F/m],
PowerDensity:[W/m3], [W/m3], [W/l], [W/in3], [W/ft3], [TW/l], [TW/m3], [TW/in3], [TW/ft3], [pW/l], [pW/m3], [pW/in3], [pW/ft3], [nW/l], [nW/m3], [nW/in3], [nW/ft3], [mW/l], [mW/m3], [mW/in3], [mW/ft3], [uW/l], [uW/m3], [uW/in3], [uW/ft3], [MW/l], [MW/m3], [MW/in3], [MW/ft3], [kW/l], [kW/m3], [kW/in3], [kW/ft3], [GW/l], [GW/m3], [GW/in3], [GW/ft3], [dW/l], [dW/m3], [dW/in3], [dW/ft3], [daW/l], [daW/m3], [daW/in3], [daW/ft3],
Power:[W], [fW], [pW], [nW], [uW], [mW], [dW], [W], [daW], [kW], [MW], [GW], [TW], [PW], [mJ/h], [J/h], [kJ/h], [MJ/h], [GJ/h], [BTU/h], [BTU/min], [BTU/s], [kBTU/h], [hp(S)], [hp(E)], [hp(H)], [hp(I)], [hp(M)], [cal/s], [kcal/h], [kcal/s], [L?],
PowerCost:[$/W], [$/kW], [$/W],
Pressure:[Pa], [Pa], [uPa], [mPa], [daPa], [hPa], [kPa], [MPa], [GPa], [atm], [ft of head], [inHg], [inH2O], [m of head], [mmHg], [at], [torr], [bar], [ubar], [mbar], [cbar], [dbar], [kbar], [Mbar], [dyn/cm2], [kgf/cm2], [kgf/m2], [kgf/mm2], [kN/cm2], [kN/m2], [kN/mm2], [MN/m2], [tf/cm2], [tf/m2], [tf/mm2], [N/mm2], [N/cm2], [N/m2], [kipf/ft2], [ksi], [lb/ft2], [psi], [lbm/(in*s2)], [bara], [barg],
PressureChangeRate:[Pa/s], [Pa/s], [Pa/min], [MPa/s], [MPa/min], [ksi/s], [ksi/min], [kPa/s], [kPa/min], [atm/s], [psi/min], [psi/s], [Mpsi/s], [Mpsi/min],
Ratio:[-], [-], [ppb], [ppm], [%], [ppt], [%], [cg/g], [cg/kg], [dag/g], [dag/kg], [dg/g], [dg/kg], [g/g], [g/kg], [hg/g], [hg/kg], [kg/g], [kg/kg], [ug/g], [ug/kg], [mg/g], [mg/kg], [ng/g], [ng/kg], [cl/l], [cl/ml], [dl/l], [dl/ml], [l/l], [l/ml], [ul/l], [ul/ml], [ml/l], [ml/ml], [nl/l], [nl/ml], [pl/l], [pl/ml],
ReactiveEnergy:[vars], [varh], [Mvarh], [kvarh],
ReactivePower:[var], [var], [Mvar], [kvar], [Gvar],
RotationalSpeed:[rad/s], [rad/s], [Hz], [kHz], [MHz], [GHz], [THz], [s?1], [bpm], [cph], [cpm],
SpecificEnergy:[J/kg], [J/kg], [kJ/kg], [MJ/kg], [BTU/lb], [cal/g], [kcal/g], [Wday/kg], [kWday/kg], [MWday/kg], [GWday/kg], [TWday/kg], [Wh/kg], [kWh/kg], [MWh/kg], [GWh/kg], [Wday/t], [kWday/t], [MWday/t], [GWday/t], [TWday/t], [Wday/t (short)], [kWday/t (short)], [MWday/t (short)], [GWday/t (short)], [TWday/t (short)],
SpecificEntropy:[J/kg*K], [J/kg*K], [J/kg*K], [kJ/kg*K], [kJ/kg*K], [MJ/kg*K], [MJ/kg*K], [J/kg*degR], [cal/g*K], [kcal/g*K], [BTU/lb*K], [BTU/lb*degR], [BTU/lb*degR],
SpecificWeight:[N/m3], [N/m3], [kgf/cm3], [kgf/m3], [kgf/mm3], [kN/cm3], [kN/m3], [kN/mm3], [kipf/ft3], [kipf/in3], [MN/m3], [N/cm3], [N/mm3], [lbf/ft3], [lbf/in3], [tf/cm3], [tf/m3], [tf/mm3],
Speed:[cm/h], [cm/min], [cm/s], [dm/min], [dm/s], [ft/h], [ft/min], [ft/s], [in/h], [in/min], [in/s], [km/h], [km/min], [km/s], [kn], [m/h], [m/min], [m/s], [um/min], [um/s], [mph], [mm/h], [mm/min], [mm/s], [nm/min], [nm/s], [ftUS/h], [ftUS/min], [ftUS/s], [yd/h], [yd/min], [yd/s], [km/h], [m/s], [mi/s],
TemperatureChangeRate:[degC/s], [degC/s], [degC/min], [cdegC/s], [dadegC/s], [ddegC/s], [hdegC/s], [kdegC/s], [udegC/s], [mdegC/s], [ndegC/s],
ThermalConductivity:[W/m*K], [W/m*K], [BTU/h*ft*degF],
ThermalResistance:[m2K/W], [m2degC/W], [m2K/kW], [cm2K/W], [cm2HrdegC/kcal], [Hrft2degF/Btu],
TorquePerLength:[N*m/m], [N*m/m], [kgf*cm/m], [kgf*m/m], [kgf*mm/m], [kN*cm/m], [kN*m/m], [kN*mm/m], [kipf*ft/ft], [kipf*in/ft], [MN*cm/m], [MN*m/m], [MN*mm/m], [Mlbf*ft/ft], [Mlbf*in/ft], [N*cm/m], [N*mm/m], [lbf*ft/ft], [lbf*in/ft], [tf*cm/m], [tf*m/m], [tf*mm/m],
Torque:[N*m], [N*m], [kN*m], [MN*m], [N*mm], [kN*mm], [MN*mm], [N*cm], [MN*cm], [pdl*ft], [lbf*ft], [lbf*in], [tf*cm], [tf*m], [tf*mm], [kN*cm], [kgf*cm], [kgf*m], [kgf*mm], [kipf*ft], [Mlbf*ft], [kipf*in], [Mlbf*in],
VolumeFlow:[af/d], [af/h], [af/m], [af/s], [cl/day], [cl/min], [cl/s], [cm3/min], [dm3/min], [ft3/h], [ft3/min], [ft3/s], [m3/day], [m3/h], [m3/min], [m3/s], [m3/s], [mm3/s], [yd3/day], [yd3/h], [yd3/min], [yd3/s], [dl/day], [dl/min], [dl/s], [kl/day], [kl/min], [kl/s], [kgal (U.S.)/min], [l/day], [l/h], [l/min], [l/s], [Ml/day], [ul/day], [ul/min], [ul/s], [ml/day], [ml/min], [ml/s], [MGD], [nl/day], [nl/min], [nl/s], [bbl/day], [bbl/h], [bbl/min], [bbl/s], [gal (U. K.)/d], [gal (imp.)/h], [gal (imp.)/min], [gal (imp.)/s], [gpd], [gal (U.S.)/h], [gal (U.S.)/min], [gal (U.S.)/s], [Mgal (imp.)/s],
VolumePerLength:[m3/m], [m3/m], [yd3/ft], [yd3/ftUS], [l/km], [l/m], [l/mm], [bbl/ft],
Volume:[m3], [m3], [hm3], [km3], [km3], [um3], [mi3], [mm3], [yd3], [in3], [hm3], [ft3], [hft3], [kft3], [Mft3], [dm3], [cm3], [l], [nl], [ul], [ml], [dl], [cl], [hl], [kl], [Ml], [pl], [ac-ft], [bf], [], [bl (imp.)], [tsp], [], [gal (imp.)], [kgal (imp.)], [Mgal (imp.)], [oz (imp.)], [pt (imp.)], [], [bl (U.S.)], [], [oz (U.S.)], [gal (U.S.)], [kgal (U.S.)], [Mgal (U.S.)], [dagal (U.S.)], [dgal (U.S.)], [hgal (U.S.)], [bbl], [], [pt (U.S.)], [qt (U.S.)], [], [],
VolumeCost:[$/m3], [$/m3], [?/m3],
WarpingMomentOfInertia:[m6], [mm6], [in6], [ft6], [dm6], [cm6], [m6],
SpecificThermalResistance:[mK/W], [mK/W], [mK/kW], [cmK/W],
ApparentPower:[kgm2/s3], [VA], [MVA], [kVA], [GVA],
Enthalpy:[J/kg], [J/kg], [kJ/kg], [MJ/kg], [BTU/lb], [cal/g], [kcal/g], [Wday/kg], [kWday/kg], [MWday/kg], [GWday/kg], [TWday/kg], [Wh/kg], [kWh/kg], [MWh/kg], [GWh/kg], [Wday/t], [kWday/t], [MWday/t], [GWday/t], [TWday/t], [Wday/t (short)], [kWday/t (short)], [MWday/t (short)], [GWday/t (short)], [TWday/t (short)],
SpecificHeatCapacity:[J/kg*K], [J/kg*K], [J/kg*K], [kJ/kg*K], [kJ/kg*K], [MJ/kg*K], [MJ/kg*K], [J/kg*degR], [cal/g*K], [kcal/g*K], [BTU/lb*K], [BTU/lb*degR], [BTU/lb*degR],
Angle:[deg], ['], ["], [g], [rad], [crad], [drad], [urad], [mrad], [nrad], [deg], [udeg], [mdeg], [ndeg], [r],
MolarFlow:[mol/s], [mol/s],
SpecificVolume:[m3/kg], [m3/kg],
VolumetricHeatTransferCoefficient:[W/m3K], [W/m3K],
Jerk:[m/s3], [km/s3], [m/s3], [dm/s3], [cm/s3], [um/s3], [mm/s3], [nm/s3],
AmountOfSubstance:[mol], [mol], [cmol], [dmol], [kmol], [Mmol], [umol], [mmol], [nmol], [pmol], [nlbmol], [ulbmol], [mlbmol], [lbmol], [klbmol], [dlbmol], [clbmol],
Duration:[ns], [ms], [us], [s], [min], [h], [day], [wk], [mo], [yr], [s],
ElectricCurrent:[A], [A], [cA], [kA], [MA], [uA], [mA], [nA], [pA],
Length:[km], [hm], [m], [m], [dm], [cm], [mm], [um], [nm], [uin], [twip], [mil], [pt], [pica], [in], [h], [ft], [yd], [fathom], [ch], [shackle], [mi], [NM], [ftUS], [ly], [kly], [Mly], [R?], [au], [pc], [kpc], [Mpc],
LuminousIntensity:[cd], [cd],
Mass:[kg], [kg], [pg], [cg], [dag], [dg], [g], [hg], [ug], [mg], [ng], [t], [kt], [Mt], [em], [oz], [lb], [st], [slug], [cwt], [cwt], [kip], [t (short)], [long tn], [Mlb], [gr],
Temperature:[K], [K], [degC], [degF], [degR],
Cost:[$], [$], [M$], [?], [PS],



Creating quantities

// Factory
Length length1 = Length.FromYard(1);

// Constructor
Length length2 = new Length(1, LengthUnit.Yard);

// Number extensions (if you added the extension namespace)
Length length3 = 1.Yard;

Parse from string (NEW)

You can now turn a string into an EngineeringUnits. This is still a new feature please create an Issue to let us know if you find something that does not work!

// Parse directly into a specific type (unit-safe)
Length L = Length.Parse("10 m");
Speed v = Speed.Parse("90 km/h");
Power P = Power.Parse("850 W");
Temperature T = Temperature.Parse("21 degC");
Area A = Area.Parse("12 m^2"); // Or use "12 m2"

//If you dont know the specific type
var u = UnknownUnit.Parse("1 kg*mm^5/s^3");
var p2 = UnknownUnit.Parse("1 kg*m^2/s^2");

//Full equaltion parser
var r1 = UnknownUnit.Eval("10m + 5in");
var r2 = UnknownUnit.Eval("1 N*m - 1 kg*m^2/s^2");
var r3 = UnknownUnit.Eval("(10 m/s) * (5 s)");

Supported syntax

  • Literals: 10 m, 5in, 1 kg*m^2/s^2, 2.5e-3 Pa
  • Operators: + - * /
  • Parentheses: ( ... )
  • Unit multiplication: * or *
  • Exponents: ^2, ^-3 and superscripts like 2, -1 (normalized)

Exporting values (edge of your system)

A good pattern is: keep units inside your domain, import/export primitive values at boundaries only.

Speed drivingSpeed = Speed.FromKilometerPerHour(60);

double mph = drivingSpeed.As(SpeedUnit.MilePerHour); // 37.28227...

string display1 = drivingSpeed.ToString(); // "60 km/h"
string display2 = drivingSpeed.ToUnit(SpeedUnit.MilePerHour).ToString(); // "37.28 mph"

Useful helpers

Absolute value

MassFlow m1 = MassFlow.FromKilogramPerSecond(-10); // -10 kg/s
MassFlow m2 = m1.Abs(); // 10 kg/s

Min / Max / Average / Mean / Sum

Length l1 = Length.FromMeter(5);
Length l2 = Length.FromMeter(15);

Length min = (l1, l2).Min();
Length avg = (l1, l2).Average();

var list = new List<Length> { l1, l2 };
Length max = list.Max();

Pow / Sqrt

Length l1 = new Length(54.3, LengthUnit.Foot);
Area a1 = l1.Pow(2);
Length l2 = a1.Sqrt();

Clamp / Limits

Power min = Power.FromWatt(-5);
Power max = Power.FromWatt(5);

Power p = Power.FromWatt(19).Clamp(min, max); // 5 W
Power q = Power.FromWatt(-19).Clamp(min, max); // -5 W

Currency support

// Update the currency rate (e.g., EUR -> USD) 1.19
ExchangeRates.UpdateRate(Currency.Euro, 1.19m);

Cost price = Cost.FromMillionUSDollar(10);
Length road = Length.FromKilometer(10);

LengthCost pricePerLength = price / road; // 1000 $/m
LengthCost euros = pricePerLength.ToUnit(LengthCostUnit.EuroPerMeter); // 840.3 EUR/m

Physical constants

EngineeringUnits includes a growing list of physical constants under Constants.

Energy e = Mass.FromKilogram(1) * Constants.SpeedOfLight.Pow(2); // ~8.99e16 J
List of constants currently included
Mechanics / Gravitation
- GravitationalConstant
- StandardGravity
- SpeedOfLight

Quantum / Fundamental
- PlanckConstant
- ReducedPlanckConstant

Electromagnetism
- VacuumElectricPermittivity
- VacuumMagneticPermeability
- ImpedanceOfFreeSpace
- CoulombConstant

Electricity / Quantum electrical standards
- ElementaryCharge
- ConductanceQuantum
- InverseConductanceQuantum
- JosephsonConstant
- VonKlitzingConstant
- MagneticFluxQuantum

Thermodynamics / Statistical mechanics
- BoltzmannConstant
- IdealGasConstant
- StefanBoltzmannConstant
- FirstRadiationConstant
- FirstRadiationConstantForSpectralRadiance
- SecondRadiationConstant
- WienWavelengthDisplacementLawConstant
- WienFrequencyDisplacementLawConstant
- WienEntropyDisplacementLawConstant

Chemistry / Molar constants
- AvogadroConstant
- FaradayConstant
- AtomicMassConstant
- MolarMassConstant
- MolarMassOfCarbon12
- MolarPlanckConstant

Atomic / Particle / Radiation physics
- ElectronMass
- ProtonMass
- NeutronMass
- BohrRadius
- ClassicalElectronRadius
- ThomsonCrossSection
- HartreeEnergy
- RydbergConstant
- QuantumOfCirculation
- FermiCouplingConstant

Magnetons
- BohrMagneton
- NuclearMagneton

Dimensionless / Ratios
- FineStructureConstant
- InverseFineStructureConstant
- ElectronGFactor
- WToZMassRatio
- WeakMixingAngle

Metrology / Reference values
- StandardAtmosphere
- StandardStatePressure
- ElectronVoltInJoules
- LuminousEfficacy540THz
- Cesium133HyperfineTransitionFrequency

What are my options for outputting to a string?

Temperature T1 = new Temperature(10.572455, TemperatureUnit.DegreeCelsius);

//This will as standard use 4 significant digits
string Output1 = T1.ToString(); // 10.57 degC

//This will use 5 significant digits
string Output2 = T1.ToString("S5"); // 10.572 degC

//Same as ToString but looks better
string Output3 = $"{T1:S5}"; // 10.572 degC

//Same as "S4" but without the unit
string Output4 = $"{T1:V4}"; // 10.57

//Display the unit without value
string Output5 = $"{T1:UnitOnly}"; // degC

//All the normal options can still be used
//https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

Tips

  • Addition/subtraction with a temperature use kelvin!
  • On the left side of = use the expected unit type for automatic unit check

Serialization (APIs / storage)

Recommended for APIs: serialize the quantity (value + unit)

Length l = new(1d, LengthUnit.Meter);

string json = JsonConvert.SerializeObject(l);
Length back = JsonConvert.DeserializeObject<Length>(json);

Recommended for DB: store value + unitName

double? value = 10;
string unit = "Meter";

Length length = value.AddUnit<LengthUnit>(unit);
Expand to see names of Units
Acceleration:[SI], [KilometerPerSecondSquared], [MeterPerSecondSquared], [DecimeterPerSecondSquared], [CentimeterPerSecondSquared], [MicrometerPerSecondSquared], [MillimeterPerSecondSquared], [NanometerPerSecondSquared], [InchPerSecondSquared], [FootPerSecondSquared], [KnotPerSecond], [KnotPerMinute], [KnotPerHour], [StandardGravity], [MillistandardGravity],
AmountOfSubstance:[SI], [Mole], [Centimole], [Decimole], [Kilomole], [Megamole], [Micromole], [Millimole], [Nanomole], [Picomole], [NanopoundMole], [MicropoundMole], [MillipoundMole], [PoundMole], [KilopoundMole], [DecipoundMole], [CentipoundMole],
Angle:[SI], [Arcminute], [Arcsecond], [Gradian], [Radian], [Centiradian], [Deciradian], [Microradian], [Milliradian], [Nanoradian], [Degree], [Microdegree], [Millidegree], [Nanodegree], [Revolution],
ApparentPower:[SI], [Voltampere], [Megavoltampere], [Kilovoltampere], [Gigavoltampere],
Area:[Acre], [Hectare], [SquareCentimeter], [SquareDecimeter], [SquareKilometer], [SquareMeter], [SquareMicrometer], [SI], [SquareMillimeter], [SquareNanometer], [SquareInch], [SquareFoot], [SquareYard], [SquareMile], [SquareNauticalMile], [SquareChain],
AreaCost:[SI], [USDollarPerSquareMeter], [MillionUSDollarPerSquareMeter], [EuroPerSquareMeter],
AreaDensity:[SI], [KilogramPerSquareMeter],
AreaMomentOfInertia:[SI], [MeterToTheFourth], [CentimeterToTheFourth], [DecimeterToTheFourth], [MillimeterToTheFourth], [InchToTheFourth], [FootToTheFourth],
BitRate:[SI], [BytePerSecond], [BitPerSecond], [KibibitPerSecond], [MebibitPerSecond], [GibibitPerSecond], [TebibitPerSecond], [PebibitPerSecond], [ExbibitPerSecond], [KibibytePerSecond], [MebibytePerSecond], [GibibytePerSecond], [TebibytePerSecond], [PebibytePerSecond], [ExbibytePerSecond], [KilobytePerSecond], [MegabytePerSecond], [GigabytePerSecond], [TerabytePerSecond], [PetabytePerSecond], [ExabytePerSecond], [KilobitPerSecond], [MegabitPerSecond], [GigabitPerSecond], [TerabitPerSecond], [PetabitPerSecond], [ExabitPerSecond],
BrakeSpecificFuelConsumption:[SI], [KilogramPerJoule], [GramPerKiloWattHour], [PoundPerMechanicalHorsepowerHour],
Capacitance:[SI], [Farad], [Kilofarad], [Megafarad], [Microfarad], [Millifarad], [Nanofarad], [Picofarad],
CoefficientOfThermalExpansion:[SI], [InverseKelvin], [InverseDegreeFahrenheit], [InverseDegreeCelsius],
Cost:[SI], [USDollar], [MillionUSDollar], [Euro], [BritishPound],
Density:[SI], [CentigramPerDeciliter], [CentigramPerLiter], [CentigramPerMilliliter], [DecigramPerDeciliter], [DecigramPerLiter], [DecigramPerMilliliter], [DecigramPerMicroliter], [GramPerCubicCentimeter], [GramPerCubicMeter], [GramPerCubicMillimeter], [GramPerDeciliter], [GramPerLiter], [GramPerMilliliter], [GramPerMicroliter], [KilogramPerCubicCentimeter], [KilogramPerCubicMeter], [KilogramPerCubicMillimeter], [KilogramPerLiter], [KilopoundPerCubicFoot], [KilopoundPerCubicInch], [MicrogramPerCubicMeter], [MicrogramPerDeciliter], [MicrogramPerLiter], [MicrogramPerMilliliter], [MicrogramPerMicroliter], [MilligramPerCubicMeter], [MilligramPerDeciliter], [MilligramPerLiter], [MilligramPerMilliliter], [MilligramPerMicroliter], [NanogramPerDeciliter], [NanogramPerLiter], [NanogramPerMilliliter], [NanogramPerMicroliter], [PicogramPerDeciliter], [PicogramPerLiter], [PicogramPerMilliliter], [PicogramPerMicroliter], [PoundPerCubicFoot], [PoundPerCubicInch], [PoundPerImperialGallon], [PoundPerUSGallon], [SlugPerCubicFoot], [TonnePerCubicCentimeter], [TonnePerCubicMeter], [TonnePerCubicMillimeter],
Duration:[Nanosecond], [Millisecond], [Microsecond], [Second], [Minute], [Hour], [Day], [Week], [Month30], [Year365], [SI],
DynamicViscosity:[SI], [PascalSecond], [MicropascalSecond], [MillipascalSecond], [PoundPerFootSecond], [Poise], [Centipoise], [NewtonSecondPerMeterSquared], [PoundForceSecondPerSquareFoot], [PoundForceSecondPerSquareInch], [Reyn],
ElectricCharge:[SI], [Coulomb], [AmpereHour], [KiloampereHour], [MegaampereHour], [MilliampereHour],
ElectricChargeDensity:[SI], [CoulombPerCubicMeter],
ElectricConductivity:[SI], [SiemensPerMeter], [SiemensPerInch], [SiemensPerFoot],
ElectricCurrent:[SI], [Ampere], [Centiampere], [Kiloampere], [Megaampere], [Microampere], [Milliampere], [Nanoampere], [Picoampere],
ElectricCurrentDensity:[SI], [AmperePerSquareMeter], [AmperePerSquareInch], [AmperePerSquareFoot],
ElectricCurrentGradient:[SI], [AmperePerSecond], [AmperePerMicrosecond], [AmperePerMillisecond], [AmperePerNanosecond],
ElectricField:[SI], [VoltPerMeter],
ElectricInductance:[SI], [Henry], [Microhenry], [Millihenry], [Nanohenry],
ElectricPotential:[SI], [Volt], [Kilovolt], [Megavolt], [Gigavolt], [Microvolt], [Millivolt],
ElectricPotentialChangeRate:[SI], [VoltPerSecond], [VoltPerMinute], [VoltPerMicrosecond], [VoltPerHour], [MillivoltPerSecond], [MillivoltPerMinute], [MillivoltPerMicrosecond], [MillivoltPerHour], [MicrovoltPerSecond], [MicrovoltPerMinute], [MicrovoltPerMicrosecond], [MicrovoltPerHour], [MegavoltPerSecond], [MegavoltPerMinute], [MegavoltPerMicrosecond], [MegavoltPerHour], [KilovoltPerSecond], [KilovoltPerMinute], [KilovoltPerMicrosecond], [KilovoltPerHour],
ElectricResistance:[SI], [Ohm], [Gigaohm], [Kiloohm], [Megaohm], [Microohm], [Milliohm],
ElectricResistivity:[SI], [OhmMeter], [OhmCentimeter], [KiloohmCentimeter], [MegaohmCentimeter], [MicroohmCentimeter], [MilliohmCentimeter], [NanoohmCentimeter], [PicoohmCentimeter], [KiloohmMeter], [MegaohmMeter], [MicroohmMeter], [MilliohmMeter], [NanoohmMeter], [PicoohmMeter],
ElectricSurfaceChargeDensity:[SI], [CoulombPerSquareMeter], [CoulombPerSquareCentimeter], [CoulombPerSquareInch],
Energy:[SI], [Millijoule], [Joule], [Kilojoule], [Megajoule], [Gigajoule], [Terajoule], [BritishThermalUnit], [KilobritishThermalUnit], [MegabritishThermalUnit], [GigabritishThermalUnit], [ElectronVolt], [KiloelectronVolt], [MegaelectronVolt], [GigaelectronVolt], [TeraelectronVolt], [Calorie], [Kilocalorie], [Megacalorie], [WattDay], [KilowattDay], [MegawattDay], [GigawattDay], [TerawattDay], [WattHour], [KilowattHour], [MegawattHour], [GigawattHour], [TerawattHour], [FootPound], [DecathermEc], [DecathermImperial], [DecathermUs], [ThermEc], [ThermImperial], [ThermUs], [Erg], [HorsepowerHour],
EnergyCost:[SI], [USDollarPerJoule], [USDollarPerKilojoule], [USDollarPerMegajoule], [USDollarPerGigajoule], [USDollarPerKilowattHour], [USDollarPerMegawattHour], [MillionUSDollarPerJoule], [MillionUSDollarPerKilojoule], [MillionUSDollarPerMegajoule], [MillionUSDollarPerGigajoule], [MillionUSDollarPerKilowattHour], [MillionUSDollarPerMegawattHour],
Enthalpy:[SI], [JoulePerKilogram], [KilojoulePerKilogram], [MegajoulePerKilogram], [BtuPerPound], [CaloriePerGram], [KilocaloriePerGram], [WattDayPerKilogram], [KilowattDayPerKilogram], [MegawattDayPerKilogram], [GigawattDayPerKilogram], [TerawattDayPerKilogram], [WattHourPerKilogram], [KilowattHourPerKilogram], [MegawattHourPerKilogram], [GigawattHourPerKilogram], [WattDayPerTonne], [KilowattDayPerTonne], [MegawattDayPerTonne], [GigawattDayPerTonne], [TerawattDayPerTonne], [WattDayPerShortTon], [KilowattDayPerShortTon], [MegawattDayPerShortTon], [GigawattDayPerShortTon], [TerawattDayPerShortTon],
Entropy:[SI], [JoulePerKelvin], [CaloriePerKelvin], [JoulePerDegreeCelsius], [KilocaloriePerKelvin], [KilojoulePerDegreeCelsius], [KilojoulePerKelvin], [MegajoulePerKelvin],
Force:[SI], [Newton], [Micronewton], [Millinewton], [Decanewton], [Kilonewton], [Meganewton], [Dyn], [TonneForce], [ShortTonForce], [PoundForce], [KilogramForce], [OunceForce], [KiloPond], [KilopoundForce], [MegapoundForce], [Poundal],
ForceChangeRate:[SI], [NewtonPerSecond], [NewtonPerMinute], [PoundForcePerSecond], [PoundForcePerMinute], [KilopoundForcePerSecond], [KilopoundForcePerMinute], [NanonewtonPerSecond], [MillinewtonPerSecond], [MicronewtonPerSecond], [CentinewtonPerSecond], [DecanewtonPerSecond], [DecinewtonPerSecond], [KilonewtonPerSecond], [DecanewtonPerMinute], [KilonewtonPerMinute],
ForcePerLength:[SI], [NewtonPerMeter], [NewtonPerCentimeter], [NewtonPerMillimeter], [KilogramForcePerCentimeter], [KilogramForcePerMeter], [KilogramForcePerMillimeter], [KilonewtonPerCentimeter], [KilonewtonPerMeter], [KilonewtonPerMillimeter], [KilopoundForcePerFoot], [KilopoundForcePerInch], [MeganewtonPerCentimeter], [MeganewtonPerMeter], [MeganewtonPerMillimeter], [MicronewtonPerCentimeter], [MicronewtonPerMeter], [MicronewtonPerMillimeter], [MillinewtonPerCentimeter], [MillinewtonPerMeter], [MillinewtonPerMillimeter], [PoundForcePerFoot], [PoundForcePerInch], [PoundForcePerYard], [TonneForcePerCentimeter], [TonneForcePerMeter], [TonneForcePerMillimeter], [NanonewtonPerCentimeter], [NanonewtonPerMeter], [NanonewtonPerMillimeter], [CentinewtonPerCentimeter], [CentinewtonPerMeter], [CentinewtonPerMillimeter], [DecanewtonPerCentimeter], [DecanewtonPerMeter], [DecanewtonPerMillimeter], [DecinewtonPerCentimeter], [DecinewtonPerMeter], [DecinewtonPerMillimeter],
Frequency:[SI], [Hertz], [Kilohertz], [Megahertz], [Gigahertz], [Terahertz], [PerSecond], [BeatPerMinute], [RevolutionsPerMinute], [RPM], [CyclePerHour], [CyclePerMinute], [RadianPerSecond],
FuelEfficiency:[SI], [KilometerPerLiter], [MilePerUkGallon], [MilePerUsGallon],
HeatFlux:[SI], [WattPerSquareMeter], [WattPerSquareInch], [WattPerSquareFoot], [BtuPerHourSquareFoot], [BtuPerMinuteSquareFoot], [BtuPerSecondSquareFoot], [BtuPerSecondSquareInch], [CaloriePerSecondSquareCentimeter], [KilocaloriePerHourSquareMeter], [KilocaloriePerSecondSquareCentimeter], [KilowattPerSquareMeter], [MicrowattPerSquareMeter], [MilliwattPerSquareMeter], [NanowattPerSquareMeter], [CentiwattPerSquareMeter], [DeciwattPerSquareMeter], [PoundForcePerFootSecond], [PoundPerSecondCubed],
HeatTransferCoefficient:[SI], [WattPerSquareMeterKelvin], [WattPerSquareMeterCelsius], [BtuPerSquareFootDegreeFahrenheit],
Illuminance:[SI], [Lux], [Kilolux], [Megalux], [Millilux],
Information:[SI], [Byte], [Bit], [Kibibit], [Mebibit], [Gibibit], [Tebibit], [Pebibit], [Exbibit], [Kibibyte], [Mebibyte], [Gibibyte], [Tebibyte], [Pebibyte], [Exbibyte], [Kilobyte], [Megabyte], [Gigabyte], [Terabyte], [Petabyte], [Exabyte], [Kilobit], [Megabit], [Gigabit], [Terabit], [Petabit], [Exabit],
Irradiance:[SI], [WattPerSquareMeter], [WattPerSquareCentimeter], [KilowattPerSquareCentimeter], [MegawattPerSquareCentimeter], [MicrowattPerSquareCentimeter], [MilliwattPerSquareCentimeter], [NanowattPerSquareCentimeter], [PicowattPerSquareCentimeter], [KilowattPerSquareMeter], [MegawattPerSquareMeter], [MicrowattPerSquareMeter], [MilliwattPerSquareMeter], [NanowattPerSquareMeter], [PicowattPerSquareMeter],
Irradiation:[SI], [JoulePerSquareMeter], [JoulePerSquareCentimeter], [JoulePerSquareMillimeter], [KilojoulePerSquareMeter], [KilowattHourPerSquareMeter], [MillijoulePerSquareCentimeter], [WattHourPerSquareMeter],
Jerk:[SI], [KilometerPerSecondCubed], [MeterPerSecondCubed], [DecimeterPerSecondCubed], [CentimeterPerSecondCubed], [MicrometerPerSecondCubed], [MillimeterPerSecondCubed], [NanometerPerSecondCubed],
KinematicViscosity:[SI], [SquareMeterPerSecond], [Stokes], [Centistokes], [Decistokes], [Kilostokes], [Microstokes], [Millistokes], [Nanostokes],
LapseRate:[SI], [DegreeCelsiusPerKilometer],
Length:[Kilometer], [Hectometer], [Meter], [SI], [Decimeter], [Centimeter], [Millimeter], [Micrometer], [Nanometer], [Microinch], [Twip], [Mil], [DtpPoint], [DtpPica], [Inch], [Hand], [Foot], [Yard], [Fathom], [Chain], [Shackle], [Mile], [NauticalMile], [UsSurveyFoot], [LightYear], [KilolightYear], [MegalightYear], [SolarRadius], [AstronomicalUnit], [Parsec], [Kiloparsec], [Megaparsec],
LengthCost:[SI], [DollarPerMeter], [EuroPerMeter],
LinearDensity:[SI], [KilogramPerMeter], [GramPerCentimeter], [GramPerMeter], [GramPerMillimeter], [KilogramPerCentimeter], [KilogramPerMillimeter], [MicrogramPerCentimeter], [MicrogramPerMeter], [MicrogramPerMillimeter], [MilligramPerCentimeter], [MilligramPerMeter], [MilligramPerMillimeter], [PoundPerFoot], [PoundPerInch],
LinearPowerDensity:[SI], [WattPerMeter], [WattPerMillimeter], [WattPerInch], [WattPerFoot], [WattPerCentimeter], [MilliwattPerMillimeter], [MilliwattPerMeter], [MilliwattPerInch], [MilliwattPerFoot], [MilliwattPerCentimeter], [MegawattPerMillimeter], [MegawattPerMeter], [MegawattPerInch], [MegawattPerFoot], [MegawattPerCentimeter], [KilowattPerMillimeter], [KilowattPerMeter], [KilowattPerInch], [KilowattPerFoot], [KilowattPerCentimeter], [GigawattPerMillimeter], [GigawattPerMeter], [GigawattPerInch], [GigawattPerFoot], [GigawattPerCentimeter],
LuminousFlux:[SI], [Lumen],
LuminousIntensity:[SI], [Candela],
MagneticField:[SI], [Tesla], [Gauss], [Milligauss], [Microtesla], [Millitesla], [Nanotesla],
MagneticFlux:[SI], [Weber],
Magnetization:[SI], [AmperePerMeter],
Mass:[SI], [Kilogram], [Picogram], [Centigram], [Decagram], [Decigram], [Gram], [Hectogram], [Microgram], [Milligram], [Nanogram], [Tonne], [Kilotonne], [Megatonne], [EarthMass], [Ounce], [Pound], [Stone], [Slug], [ShortHundredweight], [LongHundredweight], [Kilopound], [ShortTon], [LongTon], [Megapound], [Grain],
MassCost:[SI], [EuroPerKilogram], [USDollarPerKilogram], [USDollarPerTonne], [MillionUSDollarPerTonne],
MassFlow:[CentigramPerDay], [CentigramPerSecond], [DecagramPerDay], [DecagramPerSecond], [DecigramPerDay], [DecigramPerSecond], [GramPerDay], [GramPerHour], [GramPerSecond], [MegagramPerDay], [MicrogramPerSecond], [MicrogramPerDay], [MilligramPerSecond], [MilligramPerDay], [NanogramPerSecond], [NanogramPerDay], [HectogramPerDay], [HectogramPerSecond], [SI], [KilogramPerSecond], [KilogramPerMinute], [KilogramPerHour], [KilogramPerDay], [PoundPerSecond], [PoundPerMinute], [PoundPerHour], [PoundPerDay], [MegapoundPerDay], [MegapoundPerHour], [MegapoundPerMinute], [MegapoundPerSecond], [ShortTonPerHour], [TonnePerDay], [TonnePerHour],
MassFlux:[SI], [KilogramPerSecondPerSquareMeter], [GramPerHourPerSquareCentimeter], [GramPerHourPerSquareMeter], [GramPerHourPerSquareMillimeter], [GramPerSecondPerSquareCentimeter], [GramPerSecondPerSquareMeter], [GramPerSecondPerSquareMillimeter], [KilogramPerHourPerSquareCentimeter], [KilogramPerHourPerSquareMeter], [KilogramPerHourPerSquareMillimeter], [KilogramPerSecondPerSquareCentimeter], [KilogramPerSecondPerSquareMillimeter],
MassMomentOfInertia:[SI], [KilogramSquareMeter], [GramSquareCentimeter], [GramSquareDecimeter], [GramSquareMeter], [GramSquareMillimeter], [KilogramSquareCentimeter], [KilogramSquareDecimeter], [KilogramSquareMillimeter], [KilotonneSquareCentimeter], [KilotonneSquareDecimeter], [KilotonneSquareMeter], [KilotonneSquareMilimeter], [MegatonneSquareCentimeter], [MegatonneSquareDecimeter], [MegatonneSquareMeter], [MegatonneSquareMilimeter], [MilligramSquareCentimeter], [MilligramSquareDecimeter], [MilligramSquareMeter], [MilligramSquareMillimeter], [PoundSquareFoot], [PoundSquareInch], [SlugSquareFoot], [SlugSquareInch], [TonneSquareCentimeter], [TonneSquareDecimeter], [TonneSquareMeter], [TonneSquareMilimeter],
MolarEnergy:[SI], [JoulePerMole], [KilojoulePerMole], [MegajoulePerMole],
MolarEntropy:[SI], [JoulePerMoleKelvin], [KilojoulePerMoleKelvin], [MegajoulePerMoleKelvin],
MolarFlow:[SI], [MolePerSecond],
Molarity:[SI], [MolesPerCubicMeter], [MolesPerLiter], [NanomolesPerLiter], [PicomolesPerLiter], [CentimolesPerLiter], [DecimolesPerLiter], [MicromolesPerLiter], [MillimolesPerLiter],
MolarMass:[SI], [KilogramPerMole], [CentigramPerMole], [DecagramPerMole], [DecigramPerMole], [GramPerMole], [HectogramPerMole], [KilopoundPerMole], [MegapoundPerMole], [MicrogramPerMole], [MilligramPerMole], [NanogramPerMole], [PoundPerMole],
Permeability:[SI], [HenryPerMeter],
Permittivity:[SI], [FaradPerMeter],
Power:[SI], [Femtowatt], [Picowatt], [Nanowatt], [Microwatt], [Milliwatt], [Deciwatt], [Watt], [Decawatt], [Kilowatt], [Megawatt], [Gigawatt], [Terawatt], [Petawatt], [MillijoulePerHour], [JoulePerHour], [KilojoulePerHour], [MegajoulePerHour], [GigajoulePerHour], [BritishThermalUnitPerHour], [BritishThermalUnitPerMinute], [BritishThermalUnitPerSecond], [KilobritishThermalUnitPerHour], [BoilerHorsepower], [ElectricalHorsepower], [HydraulicHorsepower], [MechanicalHorsepower], [MetricHorsepower], [CaloriePerSecond], [KilocaloriePerHour], [KilocaloriePerSecond], [SolarLuminosity],
PowerCost:[SI], [USDollarPerKilowatt], [USDollarPerWatt],
PowerDensity:[SI], [WattPerCubicMeter], [WattPerLiter], [WattPerCubicInch], [WattPerCubicFoot], [TerawattPerLiter], [TerawattPerCubicMeter], [TerawattPerCubicInch], [TerawattPerCubicFoot], [PicowattPerLiter], [PicowattPerCubicMeter], [PicowattPerCubicInch], [PicowattPerCubicFoot], [NanowattPerLiter], [NanowattPerCubicMeter], [NanowattPerCubicInch], [NanowattPerCubicFoot], [MilliwattPerLiter], [MilliwattPerCubicMeter], [MilliwattPerCubicInch], [MilliwattPerCubicFoot], [MicrowattPerLiter], [MicrowattPerCubicMeter], [MicrowattPerCubicInch], [MicrowattPerCubicFoot], [MegawattPerLiter], [MegawattPerCubicMeter], [MegawattPerCubicInch], [MegawattPerCubicFoot], [KilowattPerLiter], [KilowattPerCubicMeter], [KilowattPerCubicInch], [KilowattPerCubicFoot], [GigawattPerLiter], [GigawattPerCubicMeter], [GigawattPerCubicInch], [GigawattPerCubicFoot], [DeciwattPerLiter], [DeciwattPerCubicMeter], [DeciwattPerCubicInch], [DeciwattPerCubicFoot], [DecawattPerLiter], [DecawattPerCubicMeter], [DecawattPerCubicInch], [DecawattPerCubicFoot],
Pressure:[SI], [Pascal], [Micropascal], [Millipascal], [Decapascal], [Hectopascal], [Kilopascal], [Megapascal], [Gigapascal], [Atmosphere], [FootOfHead], [InchOfMercury], [InchOfWaterColumn], [MeterOfHead], [MillimeterOfMercury], [TechnicalAtmosphere], [Torr], [Bar], [Microbar], [Millibar], [Centibar], [Decibar], [Kilobar], [Megabar], [DynePerSquareCentimeter], [KilogramForcePerSquareCentimeter], [KilogramForcePerSquareMeter], [KilogramForcePerSquareMillimeter], [KilonewtonPerSquareCentimeter], [KilonewtonPerSquareMeter], [KilonewtonPerSquareMillimeter], [MeganewtonPerSquareMeter], [TonneForcePerSquareCentimeter], [TonneForcePerSquareMeter], [TonneForcePerSquareMillimeter], [NewtonPerSquareMillimeter], [NewtonPerSquareCentimeter], [NewtonPerSquareMeter], [KilopoundForcePerSquareFoot], [KilopoundForcePerSquareInch], [PoundForcePerSquareFoot], [PoundForcePerSquareInch], [PoundPerInchSecondSquared], [BarA], [BarG],
PressureChangeRate:[SI], [PascalPerSecond], [PascalPerMinute], [MegapascalPerSecond], [MegapascalPerMinute], [KilopoundForcePerSquareInchPerSecond], [KilopoundForcePerSquareInchPerMinute], [KilopascalPerSecond], [KilopascalPerMinute], [AtmospherePerSecond], [PoundForcePerSquareInchPerMinute], [PoundForcePerSquareInchPerSecond], [MegapoundForcePerSquareInchPerSecond], [MegapoundForcePerSquareInchPerMinute],
Ratio:[SI], [DecimalFraction], [PartPerBillion], [PartPerMillion], [PartPerThousand], [PartPerTrillion], [Percent], [CentigramPerGram], [CentigramPerKilogram], [DecagramPerGram], [DecagramPerKilogram], [DecigramPerGram], [DecigramPerKilogram], [GramPerGram], [GramPerKilogram], [HectogramPerGram], [HectogramPerKilogram], [KilogramPerGram], [KilogramPerKilogram], [MicrogramPerGram], [MicrogramPerKilogram], [MilligramPerGram], [MilligramPerKilogram], [NanogramPerGram], [NanogramPerKilogram], [CentilitersPerLiter], [CentilitersPerMililiter], [DecilitersPerLiter], [DecilitersPerMililiter], [LitersPerLiter], [LitersPerMililiter], [MicrolitersPerLiter], [MicrolitersPerMililiter], [MillilitersPerLiter], [MillilitersPerMililiter], [NanolitersPerLiter], [NanolitersPerMililiter], [PicolitersPerLiter], [PicolitersPerMililiter],
ReactiveEnergy:[SI], [VoltampereReactiveHour], [MegavoltampereReactiveHour], [KilovoltampereReactiveHour],
ReactivePower:[SI], [VoltampereReactive], [MegavoltampereReactive], [KilovoltampereReactive], [GigavoltampereReactive],
RotationalSpeed:[SI], [RadianPerSecond], [Hertz], [Kilohertz], [Megahertz], [Gigahertz], [Terahertz], [PerSecond], [BeatPerMinute], [CyclePerHour], [CyclePerMinute],
SpecificEnergy:[SI], [JoulePerKilogram], [KilojoulePerKilogram], [MegajoulePerKilogram], [BtuPerPound], [CaloriePerGram], [KilocaloriePerGram], [WattDayPerKilogram], [KilowattDayPerKilogram], [MegawattDayPerKilogram], [GigawattDayPerKilogram], [TerawattDayPerKilogram], [WattHourPerKilogram], [KilowattHourPerKilogram], [MegawattHourPerKilogram], [GigawattHourPerKilogram], [WattDayPerTonne], [KilowattDayPerTonne], [MegawattDayPerTonne], [GigawattDayPerTonne], [TerawattDayPerTonne], [WattDayPerShortTon], [KilowattDayPerShortTon], [MegawattDayPerShortTon], [GigawattDayPerShortTon], [TerawattDayPerShortTon],
SpecificEntropy:[SI], [JoulePerKilogramKelvin], [JoulePerKilogramDegreeCelsius], [KilojoulePerKilogramDegreeCelsius], [KilojoulePerKilogramKelvin], [MegajoulePerKilogramDegreeCelsius], [MegajoulePerKilogramKelvin], [JoulePerKilogramRankine], [CaloriePerGramKelvin], [KilocaloriePerGramKelvin], [BtuPerPoundKelvin], [BtuPerPoundRankine], [BtuPerPoundFahrenheit],
SpecificHeatCapacity:[SI], [JoulePerKilogramKelvin], [JoulePerKilogramDegreeCelsius], [KilojoulePerKilogramDegreeCelsius], [KilojoulePerKilogramKelvin], [MegajoulePerKilogramDegreeCelsius], [MegajoulePerKilogramKelvin], [JoulePerKilogramRankine], [CaloriePerGramKelvin], [KilocaloriePerGramKelvin], [BtuPerPoundKelvin], [BtuPerPoundRankine], [BtuPerPoundFahrenheit],
SpecificThermalResistance:[SI], [MeterDegreeCelsiusPerWatt], [MeterKelvinPerKilowatt], [CentimeterKelvinPerWatt],
SpecificVolume:[SI], [CubicMeterPerKilogram],
SpecificWeight:[SI], [NewtonPerCubicMeter], [KilogramForcePerCubicCentimeter], [KilogramForcePerCubicMeter], [KilogramForcePerCubicMillimeter], [KilonewtonPerCubicCentimeter], [KilonewtonPerCubicMeter], [KilonewtonPerCubicMillimeter], [KilopoundForcePerCubicFoot], [KilopoundForcePerCubicInch], [MeganewtonPerCubicMeter], [NewtonPerCubicCentimeter], [NewtonPerCubicMillimeter], [PoundForcePerCubicFoot], [PoundForcePerCubicInch], [TonneForcePerCubicCentimeter], [TonneForcePerCubicMeter], [TonneForcePerCubicMillimeter],
Speed:[CentimeterPerHour], [CentimeterPerMinute], [CentimeterPerSecond], [DecimeterPerMinute], [DecimeterPerSecond], [FootPerHour], [FootPerMinute], [FootPerSecond], [InchPerHour], [InchPerMinute], [InchPerSecond], [KilometerPerHour], [KilometerPerMinute], [KilometerPerSecond], [Knot], [MeterPerHour], [MeterPerMinute], [MeterPerSecond], [MicrometerPerMinute], [MicrometerPerSecond], [MilePerHour], [MillimeterPerHour], [MillimeterPerMinute], [MillimeterPerSecond], [NanometerPerMinute], [NanometerPerSecond], [UsSurveyFootPerHour], [UsSurveyFootPerMinute], [UsSurveyFootPerSecond], [YardPerHour], [YardPerMinute], [YardPerSecond], [KilometerPerhour], [SI], [MilePerSecond],
Temperature:[Kelvin], [SI], [DegreeCelsius], [DegreeFahrenheit], [DegreeRankine],
TemperatureChangeRate:[SI], [DegreeCelsiusPerSecond], [DegreeCelsiusPerMinute], [CentidegreeCelsiusPerSecond], [DecadegreeCelsiusPerSecond], [DecidegreeCelsiusPerSecond], [HectodegreeCelsiusPerSecond], [KilodegreeCelsiusPerSecond], [MicrodegreeCelsiusPerSecond], [MillidegreeCelsiusPerSecond], [NanodegreeCelsiusPerSecond],
ThermalConductivity:[SI], [WattPerMeterKelvin], [BtuPerHourFootFahrenheit],
ThermalResistance:[SI], [SquareMeterDegreeCelsiusPerWatt], [SquareMeterKelvinPerKilowatt], [SquareCentimeterKelvinPerWatt], [SquareCentimeterHourDegreeCelsiusPerKilocalorie], [HourSquareFeetDegreeFahrenheitPerBtu],
Torque:[SI], [NewtonMeter], [KilonewtonMeter], [MeganewtonMeter], [NewtonMillimeter], [KilonewtonMillimeter], [MeganewtonMillimeter], [NewtonCentimeter], [MeganewtonCentimeter], [PoundalFoot], [PoundForceFoot], [PoundForceInch], [TonneForceCentimeter], [TonneForceMeter], [TonneForceMillimeter], [KilonewtonCentimeter], [KilogramForceCentimeter], [KilogramForceMeter], [KilogramForceMillimeter], [KilopoundForceFoot], [MegapoundForceFoot], [KilopoundForceInch], [MegapoundForceInch],
TorquePerLength:[SI], [NewtonMeterPerMeter], [KilogramForceCentimeterPerMeter], [KilogramForceMeterPerMeter], [KilogramForceMillimeterPerMeter], [KilonewtonCentimeterPerMeter], [KilonewtonMeterPerMeter], [KilonewtonMillimeterPerMeter], [KilopoundForceFootPerFoot], [KilopoundForceInchPerFoot], [MeganewtonCentimeterPerMeter], [MeganewtonMeterPerMeter], [MeganewtonMillimeterPerMeter], [MegapoundForceFootPerFoot], [MegapoundForceInchPerFoot], [NewtonCentimeterPerMeter], [NewtonMillimeterPerMeter], [PoundForceFootPerFoot], [PoundForceInchPerFoot], [TonneForceCentimeterPerMeter], [TonneForceMeterPerMeter], [TonneForceMillimeterPerMeter],
Volume:[SI], [CubicMeter], [HectocubicMeter], [KilocubicMeter], [CubicKilometer], [CubicMicrometer], [CubicMile], [CubicMillimeter], [CubicYard], [CubicInch], [CubicHectometer], [CubicFoot], [HectocubicFoot], [KilocubicFoot], [MegacubicFoot], [CubicDecimeter], [CubicCentimeter], [Liter], [Nanoliter], [Microliter], [Milliliter], [Deciliter], [Centiliter], [Hectoliter], [Kiloliter], [Megaliter], [Picoliter], [AcreFoot], [BoardFoot], [AuTablespoon], [ImperialBeerBarrel], [MetricTeaspoon], [MetricCup], [ImperialGallon], [KiloimperialGallon], [MegaimperialGallon], [ImperialOunce], [ImperialPint], [UsCustomaryCup], [UsBeerBarrel], [UkTablespoon], [UsOunce], [UsGallon], [KilousGallon], [MegausGallon], [DecausGallon], [DeciusGallon], [HectousGallon], [OilBarrel], [UsLegalCup], [UsPint], [UsQuart], [UsTablespoon], [UsTeaspoon],
VolumeCost:[SI], [USDollarPerCubicMeter], [EuroPerCubicMeter],
VolumeFlow:[AcreFootPerDay], [AcreFootPerHour], [AcreFootPerMinute], [AcreFootPerSecond], [CentiliterPerDay], [CentiliterPerMinute], [CentiliterPerSecond], [CubicCentimeterPerMinute], [CubicDecimeterPerMinute], [CubicFootPerHour], [CubicFootPerMinute], [CubicFootPerSecond], [CubicMeterPerDay], [CubicMeterPerHour], [CubicMeterPerMinute], [CubicMeterPerSecond], [SI], [CubicMillimeterPerSecond], [CubicYardPerDay], [CubicYardPerHour], [CubicYardPerMinute], [CubicYardPerSecond], [DeciliterPerDay], [DeciliterPerMinute], [DeciliterPerSecond], [KiloliterPerDay], [KiloliterPerMinute], [KiloliterPerSecond], [KilousGallonPerMinute], [LiterPerDay], [LiterPerHour], [LiterPerMinute], [LiterPerSecond], [MegaliterPerDay], [MicroliterPerDay], [MicroliterPerMinute], [MicroliterPerSecond], [MilliliterPerDay], [MilliliterPerMinute], [MilliliterPerSecond], [MillionUsGallonsPerDay], [NanoliterPerDay], [NanoliterPerMinute], [NanoliterPerSecond], [OilBarrelPerDay], [OilBarrelPerHour], [OilBarrelPerMinute], [OilBarrelPerSecond], [UkGallonPerDay], [UkGallonPerHour], [UkGallonPerMinute], [UkGallonPerSecond], [UsGallonPerDay], [UsGallonPerHour], [UsGallonPerMinute], [UsGallonPerSecond], [MegaukGallonPerSecond],
VolumePerLength:[SI], [CubicMeterPerMeter], [CubicYardPerFoot], [CubicYardPerUsSurveyFoot], [LiterPerKilometer], [LiterPerMeter], [LiterPerMillimeter], [OilBarrelPerFoot],
VolumetricHeatTransferCoefficient:[SI], [WattPerCubicMeterKelvin],
WarpingMomentOfInertia:[MeterToTheSixth], [MillimeterToTheSixth], [InchToTheSixth], [FootToTheSixth], [DecimeterToTheSixth], [CentimeterToTheSixth], [SI],




Performance

For most users, EngineeringUnits performance is more than sufficient. If you need maximum speed you can:

  1. work in SI units, and/or
  2. temporarily convert to primitive values, compute, then convert back.
Power p = Power.FromSI(10);
Length l = Length.FromSI(2);
Temperature t = Temperature.FromSI(4);

double pSI = (double)p.AsSI;
double lSI = (double)l.AsSI;
double tSI = (double)t.AsSI;

double resultSI = 0;

for (int i = 0; i < 1_000_000_000; i++)
{
resultSI = pSI / (lSI * tSI);
}

ThermalConductivity result = ThermalConductivity.FromSI(resultSI);

See more real world examples

Recipe-style snippets you can copy/paste and adapt.

Thermal / Heat transfer

1) Heat exchanger duty (classic)

// Q = m * cp * (Tout - Tin)
SpecificEntropy cp = 4180.JoulePerKilogramKelvin; // water-ish
MassFlow mDot = 2.KilogramPerSecond;

Temperature Tin = 20.DegreeCelsius;
Temperature Tout = 60.DegreeCelsius;

Power Q = mDot * cp * (Tout - Tin);
Console.WriteLine(Q.ToUnit(PowerUnit.Kilowatt)); // e.g. "334.4 kW"

2) Conduction through a wall (Fourier)

// q = k * A * DT / L
ThermalConductivity k = 1.4.WattPerMeterKelvin;
Area A = 12.SquareMeter;
Length L = 0.24.Meter;

Temperature Tin = 21.DegreeCelsius;
Temperature Tout = -2.DegreeCelsius;

Power q = k * A * (Tin - Tout) / L;

3) Radiation heat loss (Stefan-Boltzmann)

// q = e s A (T1^4 - T2^4)
Ratio epsilon = 0.9.DecimalFraction;
Area A = 2.SquareMeter;

Temperature T1 = 500.Kelvin;
Temperature T2 = 300.Kelvin;

Power q = epsilon * Constants.StefanBoltzmannConstant * A * (T1.Pow(4) - T2.Pow(4));

4) Round-trip example (SI - Imperial)

Temperature room = 21.DegreeCelsius;

Temperature f = room.ToUnit(TemperatureUnit.DegreeFahrenheit);
Temperature back = f.ToUnit(TemperatureUnit.DegreeCelsius);

Console.WriteLine($"{room} -> {f} -> {back}");
Fluids / HVAC

1) Volumetric flow from duct velocity

// Qv = v * A
Speed v = 5.MeterPerSecond;
Area A = 0.25.SquareMeter;

VolumeFlow Qv = v * A; // m3/s
Console.WriteLine(Qv);

2) Mass flow from density and volumetric flow

// m = r * Qv
Density rho = 1.2.KilogramPerCubicMeter; // air-ish
VolumeFlow Qv = 0.8.CubicMeterPerSecond;

MassFlow mDot = rho * Qv;

3) Pressure from head (pump/hydraulics quick check)

// Dp = r g h
Density rho = 998.KilogramPerCubicMeter; // water-ish
Length h = 18.Meter;

Pressure dp = rho * Constants.StandardGravity * h; // Pa
Console.WriteLine(dp.ToUnit(PressureUnit.Bar));

4) Reynolds number (dimensionless sanity check)

// Re = (r * v * D) / m -> should be dimensionless
Density rho = 1.2.KilogramPerCubicMeter;
Speed v = 8.MeterPerSecond;
Length D = 0.2.Meter;
DynamicViscosity mu = 1.8e-5.PascalSecond;

Ratio Re = (rho * v * D) / mu;
Console.WriteLine(Re);

5) Convert flow to US units (m3/s - CFM)

VolumeFlow Qv = 0.35.CubicMeterPerSecond;

var cfm = Qv.ToUnit(VolumeFlowUnit.CubicFootPerMinute);
Console.WriteLine(cfm); // e.g. "741.6 ft3/min"
Mechanical

1) Density (and catching unit order mistakes)

Mass m = 10.Kilogram;
Volume V = 4.CubicMeter;

Density rho = m / V; // OK: kg/m3

// Compile-time error (analyzer): m3/kg != kg/m3
Density wrong = V / m;

2) Kinetic energy

// Ek = 0.5 * m * v2
Mass m = 1200.Kilogram; // car-ish
Speed v = 27.MeterPerSecond; // ~97 km/h

Energy Ek = 0.5m * m * v.Pow(2);

3) Torque and power

// P = t * o
Torque tau = 250.NewtonMeter;
RotationalSpeed omega = 3000.RPM;

Power P = tau * omega;
Console.WriteLine(P.ToUnit(PowerUnit.MechanicalHorsepower));

4) Pressure force on a piston

// F = p * A
Pressure p = 10.Bar;
Area A = 0.01.SquareMeter;

Force F = p * A;
Console.WriteLine(F);
Electrical

1) Ohm's law + electrical power

ElectricResistance R = 12.Ohm;
ElectricCurrent I = 3.Ampere;

ElectricPotential V = I * R;
Power P = V * I;

Console.WriteLine($"{V}, {P}");

2) Energy usage over time

Power P = 850.Watt;
Duration t = 3.Hour;

Energy E = P * t;
Console.WriteLine(E.ToUnit(EnergyUnit.KilowattHour));

3) Capacitor energy

// E = 0.5 * C * V2
Capacitance C = 470.Microfarad;
ElectricPotential V = 24.Volt;

Energy E = 0.5m * C * V.Pow(2);
Console.WriteLine(E);
Chemistry / thermo

1) Ideal gas law (PV = nRT)

Pressure P = 101325.Pascal;
Volume V = 1.CubicMeter;
AmountOfSubstance n = 40.Mole;

// T = (P * V) / (n * R)
Temperature T = (P * V) / (n * Constants.IdealGasConstant);
Console.WriteLine(T);

2) Molar concentration (molarity)

// c = n / V
AmountOfSubstance n = 0.75.Mole;
Volume V = 0.5.Liter;

Molarity c = n / V;
Console.WriteLine(c); // mol/L (depending on chosen unit)
Cost / "engineering meets business"

1) Energy cost from power and time

Power avgLoad = 12.Kilowatt;
Duration t = 7.Hour;
Energy E = avgLoad * t;

EnergyCost price = 0.25.USDollarPerKilowattHour;
Cost total = E * price;

Console.WriteLine(total);

2) Cost per length (budgeting)

Cost budget = 2.MillionUSDollar;
Length road = 3.Kilometer;

LengthCost costPerMeter = budget / road;
Console.WriteLine(costPerMeter);

3) Currency conversion in a unit expression

ExchangeRates.UpdateRate(Currency.Euro, 1.19m); // 1 EUR -> 1.19 USD

LengthCost usd = 840.3.USDollarPerMeter;
LengthCost eur = usd.ToUnit(LengthCostUnit.EuroPerMeter);

Console.WriteLine($"{usd} -> {eur}");

Documentation / Custom units


Contributing

Contributions are welcome! The most helpful contributions are:

  • real-world example snippets (engineering, physics, chemistry)
  • bug reports with minimal repro
  • unit additions + tests

Open an issue and show how you use EngineeringUnits: https://github.com/MadsKirkFoged/EngineeringUnits/issues


License

MIT -- see LICENSE

About

Working with units made easy with automatic unit-check and converting between units

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages