Skip to content

Commit

Permalink
Reverting the ShouldRoundUp logic to not change for custom numeric fo…
Browse files Browse the repository at this point in the history
…rmat strings. (dotnet/coreclr#25400)

Commit migrated from dotnet/coreclr@d9d31e6
  • Loading branch information
tannergooding authored Jun 26, 2019
1 parent eff6081 commit 99b2eee
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2436,26 +2436,13 @@ bool ShouldRoundUp(byte* dig, int i, NumberBufferKind numberKind, bool isCorrect
return false;
}

if (digit > '5')
{
// Values greater than 5 always round up
return true;
}

if (digit != '5')
{
// Values less than 5 always round down
return false;
}

if (numberKind != NumberBufferKind.FloatingPoint)
{
// Non floating-point values always round up for 5
return true;
}
// Values greater than or equal to 5 should round up, otherwise we round down. The IEEE
// 754 spec actually dictates that ties (exactly 5) should round to the nearest even number
// but that can have undesired behavior for custom numeric format strings. This probably
// needs further thought for .NET 5 so that we can be spec compliant and so that users
// can get the desired rounding behavior for their needs.

// Floating-point values round up if there is a non-zero tail
return (dig[i + 1] != '\0');
return (digit >= '5');
}
}

Expand Down

0 comments on commit 99b2eee

Please sign in to comment.