Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Changed parsing of numerical types to use TryParse to handle exceeded…
… long-type value range and fallback to double type for such cases.
  • Loading branch information
TobiasPott committed Aug 25, 2020
commit 4b33bcb6130f90158ddd2bb8fbc6e95bcc80d9f7
16 changes: 14 additions & 2 deletions Parse/Infrastructure/Utilities/JsonUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,20 @@ private bool ParseNumber(out object output)
}
else
{
output = Int64.Parse(m.Value, CultureInfo.InvariantCulture);
return true;
// try to parse to a long assuming it is an integer value (this might fail due to value range differences when storing as double without decimal point or exponent)
if (Int64.TryParse(m.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out long longValue))
{
output = longValue;
return true;
}
// try to parse as double again (most likely due to value range exceeding long type
else if (Double.TryParse(m.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out double doubleValue))
{
output = doubleValue;
return true;
}
else
return false;
}
}

Expand Down