diff --git a/PreciseNumber.Test/PreciseNumberConversionTests.cs b/PreciseNumber.Test/PreciseNumberConversionTests.cs index bb69740..e0ef1da 100644 --- a/PreciseNumber.Test/PreciseNumberConversionTests.cs +++ b/PreciseNumber.Test/PreciseNumberConversionTests.cs @@ -84,6 +84,18 @@ public void FromDecimalIsExact() AssertFromInAllModes(0.0000000000000000000000000001m, "0.0000000000000000000000000001"); } + [TestMethod] + public void FromDecimalWithOnlyZerosAfterThePoint() + { + // Trimming the zeros of "10.0" leaves "10." with an empty fraction, which is valid text for + // ten, not a malformed rendering. This runs in Debug, where a failed assert ends the process. + Assert.AreEqual(P("10"), 10.0m.ToPreciseNumber()); + Assert.AreEqual(P("100"), 100.00m.ToPreciseNumber()); + Assert.AreEqual(P("-20"), (-20.0m).ToPreciseNumber()); + AssertFromInAllModes(10.0m, "10"); + AssertFromInAllModes(-1200.000m, "-1200"); + } + [TestMethod] public void FromBinaryFloatingPointUsesDecimalText() { diff --git a/PreciseNumber/PreciseNumber.cs b/PreciseNumber/PreciseNumber.cs index fc17624..7dd2164 100644 --- a/PreciseNumber/PreciseNumber.cs +++ b/PreciseNumber/PreciseNumber.cs @@ -667,8 +667,6 @@ private static PreciseNumber ParseRenderedFloat(ReadOnlySpan text) ReadOnlySpan fractionalComponent = decimalIndex < 0 ? "0".AsSpan() : text[(decimalIndex + 1)..]; exponentValue -= fractionalComponent.Length; - Debug.Assert(fractionalComponent.Length != 0 || integerComponent.TrimStart("-").Length == 1, $"Unexpected format: {text}"); - int digitLength = integerComponent.Length + fractionalComponent.Length; char[]? rentedDigits = digitLength > MaxStackAllocChars ? ArrayPool.Shared.Rent(digitLength) : null; Span stackDigits = stackalloc char[MaxStackAllocChars];