You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Change the XML summary for rounding modes
* Improve the existing code snippet for round to nearest modes with interpolated strings and more descriptive variable names
* Replace 'Remarks' section with 'Rounding to nearest'
* Added 'Directed rounding' section
Copy file name to clipboardExpand all lines: xml/System/MidpointRounding.xml
+25-12Lines changed: 25 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -52,15 +52,15 @@
52
52
<summary>Specifies how mathematical rounding methods should process a number that is midway between two numbers.</summary>
53
53
<remarks>
54
54
<formattype="text/markdown"><![CDATA[
55
+
## Remarks
56
+
Use `MidpointRounding` with appropriate overloads of <xref:System.Math.Round%2A?displayProperty=nameWithType> to provide more control of the rounding process.
57
+
58
+
### Round to nearest
59
+
A round-to-nearest operation takes an original number with an implicit or specified precision; examines the next digit, which is at that precision plus one; and returns the nearest number with the same precision as the original number. For positive numbers, if the next digit is from 0 through 4, the nearest number is toward negative infinity. If the next digit is from 6 through 9, the nearest number is toward positive infinity. For negative numbers, if the next digit is from 0 through 4, the nearest number is toward positive infinity. If the next digit is from 6 through 9, the nearest number is toward negative infinity.
55
60
56
-
## Remarks
57
-
Use `MidpointRounding` with appropriate overloads of <xref:System.Math.Round%2A?displayProperty=nameWithType> to provide more control of the rounding process.
61
+
In the previous cases, the `MidpointRounding.AwayFromZero` and `MidpointRounding.ToEven` do not affect the result of the rounding operation. However, if the next digit is 5, which is the midpoint between two possible results, and all remaining digits are zero or there are no remaining digits, the nearest number is ambiguous. In this case, the round-to-nearest modes in `MidpointRounding` enable you to specify whether the rounding operation returns the nearest number away from zero or the nearest even number.
58
62
59
-
A rounding operation takes an original number with an implicit or specified precision; examines the next digit, which is at that precision plus one; and returns the nearest number with the same precision as the original number. For positive numbers, if the next digit is from 0 through 4, the nearest number is toward negative infinity. If the next digit is from 6 through 9, the nearest number is toward positive infinity. For negative numbers, if the next digit is from 0 through 4, the nearest number is toward positive infinity. If the next digit is from 6 through 9, the nearest number is toward negative infinity.
60
-
61
-
In the previous cases, the `MidpointRounding` enumeration does not affect the result of the rounding operation. However, if the next digit is 5, which is the midpoint between two possible results, and all remaining digits are zero or there are no remaining digits, the nearest number is ambiguous. In this case, the `MidpointRounding` enumeration enables you to specify whether the rounding operation returns the nearest number away from zero or the nearest even number.
62
-
63
-
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with the values of `MidpointRounding`. The precision used to round the numbers is zero, which means the number after the decimal point affects the rounding operation. For example, for the number -2.5, the digit after the decimal point is 5. Because that digit is the midpoint, you can use a `MidpointRounding` value to determine the result of rounding. If `AwayFromZero` is specified, -3 is returned because it is the nearest number away from zero with a precision of zero. If `ToEven` is specified, -2 is returned because it is the nearest even number with a precision of zero.
63
+
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with round-to-nearest modes. The precision used to round the numbers is zero, which means the number after the decimal point affects the rounding operation. For example, for the number -2.5, the digit after the decimal point is 5. Because that digit is the midpoint, you can use a `MidpointRounding` value to determine the result of rounding. If `AwayFromZero` is specified, -3 is returned because it is the nearest number away from zero with a precision of zero. If `ToEven` is specified, -2 is returned because it is the nearest even number with a precision of zero.
A directed rounding operation takes an original number with an implicit or specified precision and returns the next number closest to some predefined one with the same precision as the original number. Directed modes on `MidpointRounding` control toward which predefined number the rounding is performed.
78
+
79
+
The following table demonstrates the results of rounding some negative and positive numbers in conjunction with directed rounding modes. The precision used to round the numbers is zero, which means the number before the decimal point is affected by the rounding operation.
<summary>When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.</summary>
142
+
<summary>Round to nearest mode: when a number is halfway between two others, it is rounded toward the nearest number that is away from zero.</summary>
130
143
</Docs>
131
144
</Member>
132
145
<MemberMemberName="ToEven">
@@ -169,7 +182,7 @@
169
182
</ReturnValue>
170
183
<MemberValue>0</MemberValue>
171
184
<Docs>
172
-
<summary>When a number is halfway between two others, it is rounded toward the nearest even number.</summary>
185
+
<summary>Round to nearest mode: when a number is halfway between two others, it is rounded toward the nearest even number.</summary>
173
186
</Docs>
174
187
</Member>
175
188
<MemberMemberName="ToNegativeInfinity">
@@ -203,7 +216,7 @@
203
216
</ReturnValue>
204
217
<MemberValue>3</MemberValue>
205
218
<Docs>
206
-
<summary>When a number is halfway between two others, it is rounded toward the result closest to and no greater than the infinitely precise result.</summary>
219
+
<summary>Directed mode: the number is rounded down, with the result closest to and no greater than the infinitely precise result.</summary>
207
220
</Docs>
208
221
</Member>
209
222
<MemberMemberName="ToPositiveInfinity">
@@ -237,7 +250,7 @@
237
250
</ReturnValue>
238
251
<MemberValue>4</MemberValue>
239
252
<Docs>
240
-
<summary>When a number is halfway between two others, it is rounded toward the result closest to and no less than the infinitely precise result.</summary>
253
+
<summary>Directed mode: the number is rounded up, with the result closest to and no less than the infinitely precise result.</summary>
241
254
</Docs>
242
255
</Member>
243
256
<MemberMemberName="ToZero">
@@ -271,7 +284,7 @@
271
284
</ReturnValue>
272
285
<MemberValue>2</MemberValue>
273
286
<Docs>
274
-
<summary>When a number is halfway between two others, it is rounded toward the result closest to and no greater in magnitude than the infinitely precise result.</summary>
287
+
<summary>Directed mode: the number is rounded toward zero, with the result closest to and no greater in magnitude than the infinitely precise result.</summary>
0 commit comments