Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion UnitsNet.Tests/CustomCode/ParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ParseTests
[InlineData("1e-3 km", 1)]
[InlineData("5.5 m", 5.5)]
[InlineData("500,005 m", 500005)]
[InlineData("NaN m", double.NaN)]
public void ParseLengthToMetersUsEnglish(string s, double expected)
{
CultureInfo usEnglish = new CultureInfo("en-US");
Expand Down Expand Up @@ -235,4 +236,4 @@ private static string AssertExceptionAndGetFullTypeName(Action code)
}

}
}
}
2 changes: 1 addition & 1 deletion UnitsNet/CustomCode/QuantityParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal static TQuantity Parse<TQuantity, TUnitType>([NotNull] string str,

string unitsRegex = $"({String.Join("|", unitAbbreviations)})";

string regexString = string.Format(@"(?:\s*(?<value>[-+]?{0}{1}{2}{3})?{4}{5}",
string regexString = string.Format(@"(?:\s*(?<value>(?:[-+]?{0}{1}|NaN){2}{3})?{4}{5}",
numRegex, // capture base (integral) Quantity value
exponentialRegex, // capture exponential (if any), end of Quantity capturing
@"\s?", // ignore whitespace (allows both "1kg", "1 kg")
Expand Down