From d9d31e6b03758abdd1621cf9da6fdd35b778a6fa Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 25 Jun 2019 22:36:36 -0700 Subject: [PATCH] Reverting the ShouldRoundUp logic to not change for custom numeric format strings. (#25400) --- .../shared/System/Number.Formatting.cs | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs index f00c8e5..6047e93 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs @@ -2436,26 +2436,13 @@ namespace System 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'); } } -- 2.7.4