Repository navigation
Home
Marcus Ackre Medina edited this page Jul 20, 2026
·
2 revisions
Fluent weight unit conversion for .NET 10+ — metric, British (imperial, Troy and Apothecary), US customary, and historical Swedish units, all through one strongly-typed Weight struct.
dotnet add package MarcusMedina.Units.WeightA raw
doubledoesn't tell you whether it's grams, pounds, or skålpund — and mixing those up is an easy mistake to make in real code, or in a student's maths homework. I wanted aWeightstruct where the unit is part of the type, so the compiler catches the mix-up instead of you catching it in production. Every conversion is broken into the same small, explicit step you'd walk a student through by hand, rather than buried inside one opaque formula.
-
New to C#? The API reads like plain English —
1.Stone().ToKilograms()— a good way to see extension methods and structs used for something concrete. - Professional? Zero dependencies, strongly-typed, fully tested. Drop it in wherever you need to convert weights without hand-rolling the maths again.
using MarcusMedina.Units.Weight.Metric;
using MarcusMedina.Units.Weight.British;
using MarcusMedina.Units.Weight.SwedishOld;
// Create a Weight from any supported unit
Weight package = 2.5.Kilograms();
Weight person = 11.Stone();
// Convert to whatever unit you need
double pounds = person.ToPounds(); // 154
double skalpund = package.ToSkålpund(); // ≈ 5.88
// Arithmetic works directly on Weight values
Weight total = package + 1.Pounds();
// Comparisons
bool heavier = person > package;