Skip to content

Commit

Permalink
Fix double => decimal parse back
Browse files Browse the repository at this point in the history
  • Loading branch information
lewischeng-ms committed Nov 13, 2015
1 parent 0cdf84b commit bfd173f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,11 @@ private static ExpressionTokenKind MakeBestGuessOnNoSuffixStr(string numericStr,
decimal doubleToDecimalR;
decimal doubleToDecimalN;

// To keep the full presion of the current value, which if necessary is all 17 digits of precision supported by the Double type.
bool doubleCanBeDecimalR = decimal.TryParse(tmpDouble.ToString("R", CultureInfo.InvariantCulture), NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out doubleToDecimalR);
// To keep the full precision of the current value, which if necessary is all 17 digits of precision supported by the Double type.
bool doubleCanBeDecimalR = decimal.TryParse(tmpDouble.ToString("R", CultureInfo.InvariantCulture), NumberStyles.Float, CultureInfo.InvariantCulture, out doubleToDecimalR);

// To cover the scientific notation case, such as 1e+19 in the tmpDouble
bool doubleCanBeDecimalN = decimal.TryParse(tmpDouble.ToString("N29", CultureInfo.InvariantCulture), NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out doubleToDecimalN);
bool doubleCanBeDecimalN = decimal.TryParse(tmpDouble.ToString("N29", CultureInfo.InvariantCulture), NumberStyles.Number, CultureInfo.InvariantCulture, out doubleToDecimalN);

if ((doubleCanBeDecimalR && doubleToDecimalR != tmpDecimal) || (!doubleCanBeDecimalR && doubleCanBeDecimalN && doubleToDecimalN != tmpDecimal))
{
Expand Down

0 comments on commit bfd173f

Please sign in to comment.