summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanner Gooding <tagoo@outlook.com>2019-06-25 22:36:36 -0700
committerGitHub <noreply@github.com>2019-06-25 22:36:36 -0700
commitd9d31e6b03758abdd1621cf9da6fdd35b778a6fa (patch)
tree42ea8a9fb4aac1620a49a7a04241343bb3151229
parentd53a3ee7d2e772f7fad8a96657adc606d63ea02a (diff)
downloadcoreclr-d9d31e6b03758abdd1621cf9da6fdd35b778a6fa.tar.gz
coreclr-d9d31e6b03758abdd1621cf9da6fdd35b778a6fa.tar.bz2
coreclr-d9d31e6b03758abdd1621cf9da6fdd35b778a6fa.zip
Reverting the ShouldRoundUp logic to not change for custom numeric format strings. (#25400)
-rw-r--r--src/System.Private.CoreLib/shared/System/Number.Formatting.cs25
1 files 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 f00c8e50c0..6047e9357f 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');
}
}