Skip to content

Commit e2ae020

Browse files
Fixes two edge cases with the mapping of double types (#887)
Mirrors PR #886 on the maintenance branch
1 parent 1b875b7 commit e2ae020

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

samples/xlsx/TestIssue409.xlsx

6.35 KB
Binary file not shown.

samples/xlsx/TestIssue881.xlsx

6.25 KB
Binary file not shown.

src/MiniExcel/Utils/TypeHelper.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,17 @@ public static bool IsNumericType(Type type, bool isNullableUnderlyingType = fals
199199
}
200200
else if (pInfo.ExcludeNullableType == typeof(double)) // && (!Regex.IsMatch(itemValue.ToString(), @"^-?\d+(\.\d+)?([eE][-+]?\d+)?$") || itemValue.ToString().Trim().Equals("NaN")))
201201
{
202-
var invariantString = Convert.ToString(itemValue, CultureInfo.InvariantCulture);
203-
newValue = double.TryParse(invariantString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value) ? value : double.NaN;
202+
if (double.TryParse(Convert.ToString(itemValue, config.Culture), NumberStyles.Any, config.Culture, out var doubleValue))
203+
{
204+
newValue = doubleValue;
205+
}
206+
else
207+
{
208+
var invariantString = Convert.ToString(itemValue, CultureInfo.InvariantCulture);
209+
newValue = double.TryParse(invariantString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)
210+
? value
211+
: throw new InvalidCastException($"Value \"{itemValue}\" cannot be cast to double");
212+
}
204213
}
205214
else if (pInfo.ExcludeNullableType == typeof(bool))
206215
{

0 commit comments

Comments
 (0)