Skip to content

Commit aa9f5b8

Browse files
committed
Merge pull request #25 from strvmarv/add-pounds
Add pounds (Imperial)
2 parents ce9fa5c + e99b2dd commit aa9f5b8

File tree

7 files changed

+38
-0
lines changed

7 files changed

+38
-0
lines changed

Src/UnitsNet/GeneratedCode/MassUnit.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ public double Nanograms
140140
get { return (Kilograms - (0)) / 1E-12; }
141141
}
142142

143+
/// <summary>
144+
/// Get Mass in Pounds.
145+
/// </summary>
146+
/// <remarks>Example: x = (y - b) / a where x is value in Pounds and y is value in base unit Kilograms.</remarks>
147+
public double Pounds
148+
{
149+
get { return (Kilograms - (0)) / 0.45359237; }
150+
}
151+
143152
/// <summary>
144153
/// Get Mass in ShortTons.
145154
/// </summary>
@@ -275,6 +284,15 @@ public static Mass FromNanograms(double nanograms)
275284
return new Mass(1E-12 * nanograms + 0);
276285
}
277286

287+
/// <summary>
288+
/// Get Mass from Pounds.
289+
/// </summary>
290+
/// <remarks>Example: y = ax + b where x is value in Pounds and y is value in base unit Kilograms.</remarks>
291+
public static Mass FromPounds(double pounds)
292+
{
293+
return new Mass(0.45359237 * pounds + 0);
294+
}
295+
278296
/// <summary>
279297
/// Get Mass from ShortTons.
280298
/// </summary>

Src/UnitsNet/GeneratedCode/UnitConverter.g.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ private static bool TryConvertFromMass(double value, Unit fromUnit, Unit toUnit,
319319
return TryConvert(Mass.FromNanograms(value), toUnit, out newValue);
320320
case Unit.ShortTon:
321321
return TryConvert(Mass.FromShortTons(value), toUnit, out newValue);
322+
case Unit.Pound:
323+
return TryConvert(Mass.FromPounds(value), toUnit, out newValue);
322324
case Unit.LongTon:
323325
return TryConvert(Mass.FromLongTons(value), toUnit, out newValue);
324326

@@ -803,6 +805,9 @@ private static bool TryConvert(Mass value, Unit toUnit, out double newValue)
803805
case Unit.ShortTon:
804806
newValue = value.ShortTons;
805807
return true;
808+
case Unit.Pound:
809+
newValue = value.Pounds;
810+
return true;
806811
case Unit.LongTon:
807812
newValue = value.LongTons;
808813
return true;

Src/UnitsNet/Unit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public enum Unit
6666
/// <remarks>http://en.wikipedia.org/wiki/Short_ton</remarks>
6767
[Mass(907.18474)] ShortTon,
6868

69+
/// <summary>
70+
/// The pound or pound-mass (abbreviations: lb, lbm) is a unit of mass used in the imperial, United States customary and other systems of measurement. A number of different definitions have been used, the most common today being the international avoirdupois pound which is legally defined as exactly 0.45359237 kilograms, and which is divided into 16 avoirdupois ounces.
71+
/// </summary>
72+
[Mass(0.45359237)] Pound,
73+
6974
/// <summary>
7075
/// Long ton (weight ton or Imperial ton) is a unit of mass equal to 2,240 pounds (1,016 kg) and is the name for the unit called the "ton" in the avoirdupois or Imperial system of measurements that was used in the United Kingdom and several other Commonwealth countries before metrication.
7176
/// </summary>

Src/UnitsNet/UnitSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ private void CreateCultureInvariants()
326326

327327
// Mass (imperial)
328328
MapUnitToAbbreviation(Unit.ShortTon, "short tn");
329+
MapUnitToAbbreviation(Unit.Pound, "lb");
329330
MapUnitToAbbreviation(Unit.LongTon, "long tn");
330331

331332
// Pressures

Tests/CustomCode/MassTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public override double ShortTonsInOneKilogram
8888
get { return 0.00110231; }
8989
}
9090

91+
public override double PoundsInOneKilogram
92+
{
93+
get { return 2.2046226218487757d; }
94+
}
95+
9196
public override double TonnesInOneKilogram
9297
{
9398
get { return 1E-3; }

Tests/GeneratedCode/MassTestsBase.g.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract partial class MassTestsBase
4848
public abstract double MicrogramsInOneKilogram { get; }
4949
public abstract double MilligramsInOneKilogram { get; }
5050
public abstract double NanogramsInOneKilogram { get; }
51+
public abstract double PoundsInOneKilogram { get; }
5152
public abstract double ShortTonsInOneKilogram { get; }
5253
public abstract double TonnesInOneKilogram { get; }
5354

@@ -67,6 +68,7 @@ public void KilogramToMassUnits()
6768
Assert.AreEqual(MicrogramsInOneKilogram, kilogram.Micrograms, Delta);
6869
Assert.AreEqual(MilligramsInOneKilogram, kilogram.Milligrams, Delta);
6970
Assert.AreEqual(NanogramsInOneKilogram, kilogram.Nanograms, Delta);
71+
Assert.AreEqual(PoundsInOneKilogram, kilogram.Pounds, Delta);
7072
Assert.AreEqual(ShortTonsInOneKilogram, kilogram.ShortTons, Delta);
7173
Assert.AreEqual(TonnesInOneKilogram, kilogram.Tonnes, Delta);
7274
}
@@ -87,6 +89,7 @@ public void ConversionRoundTrip()
8789
Assert.AreEqual(1, Mass.FromMicrograms(kilogram.Micrograms).Kilograms, Delta);
8890
Assert.AreEqual(1, Mass.FromMilligrams(kilogram.Milligrams).Kilograms, Delta);
8991
Assert.AreEqual(1, Mass.FromNanograms(kilogram.Nanograms).Kilograms, Delta);
92+
Assert.AreEqual(1, Mass.FromPounds(kilogram.Pounds).Kilograms, Delta);
9093
Assert.AreEqual(1, Mass.FromShortTons(kilogram.ShortTons).Kilograms, Delta);
9194
Assert.AreEqual(1, Mass.FromTonnes(kilogram.Tonnes).Kilograms, Delta);
9295
}

Tests/GeneratedCode/UnitConverterTests.g.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void KilogramToMassUnits()
6565
Assert.AreEqual(t.MicrogramsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Microgram), Delta);
6666
Assert.AreEqual(t.NanogramsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Nanogram), Delta);
6767
Assert.AreEqual(t.ShortTonsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.ShortTon), Delta);
68+
Assert.AreEqual(t.PoundsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.Pound), Delta);
6869
Assert.AreEqual(t.LongTonsInOneKilogram, UnitConverter.Convert(1, Unit.Kilogram, Unit.LongTon), Delta);
6970
}
7071
[Test]

0 commit comments

Comments
 (0)