Skip to content

Commit 61313cc

Browse files
committed
Improved precision of Mil constant in Length. Fixed test.
1 parent 0b056db commit 61313cc

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Src/UnitsNet/Length.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace UnitsNet
2828
/// </summary>
2929
public struct Length : IComparable, IComparable<Length>
3030
{
31+
private const double MilsToMetersRatio = 2.54E-5;
3132
public readonly double Meters;
3233

3334
/// <summary>
@@ -97,7 +98,7 @@ public double Microinch
9798

9899
public double Mil
99100
{
100-
get { return Meters * 39370.0787; }
101+
get { return Meters / MilsToMetersRatio; }
101102
}
102103

103104
#endregion
@@ -185,9 +186,9 @@ public static Length FromMicroinches(double mi)
185186
return FromMeters(mi / 39370078.7);
186187
}
187188

188-
public static Length FromMils(double m)
189+
public static Length FromMils(double mils)
189190
{
190-
return FromMeters(m / 39370.0787);
191+
return FromMeters(mils*MilsToMetersRatio);
191192
}
192193

193194
#endregion

Tests/LengthTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void MetersToDistanceUnits()
2626
Assert.AreEqual(3.28084, meter.Feet, Delta);
2727
Assert.AreEqual(39.3701, meter.Inches, Delta);
2828
Assert.AreEqual(39370078.7, meter.Microinch, Delta);
29-
Assert.AreEqual(39370.0787, meter.Mil, Delta);
29+
Assert.AreEqual(39370.07874015, meter.Mil, Delta);
3030
}
3131

3232
[Test]

0 commit comments

Comments
 (0)