Round: rounds the point value to the nearest integer to convert the specified pointf to a point object.
See the following example:
Math. round (3.44, 1); // returns 3.4. 4
Math. round (3.451, 1); // after returns 3.5, a non-zero entry
Math. round (3.45, 1); // returns 3.4. After, check for parity.
Math. round (3.75, 1); // after returns 3.8, check for parity. Before five, it is odd to enter one.
Math. round (3.46, 1); // returns 3.5. Six entries
If we want to implement our traditional rounding function, a relatively simple method is to add 0.0000000001 to the back of the number, a small number. because "after five is not zero, it can be ensured that 5 must enter one.
Of course, you can also write functions by yourself. The following code is provided:
Public static decimal unit = 0.0.1m
Static public decimal round (decimal d)
{
Return round (d, unit)
}
Static public decimal round (decimal d, decimal unit)
{
Decimal rm = d % unit;
Decimal result = d-rm;
If (rm> = unit/2)
{
Result + = unit;
}
Return result;
}
Note that round is much more powerful than it seems to be simply because it can fully be a specific number of decimal places. All other rounds are always zero decimal. For example:
N = 3.145;
A = system. math. round (n, 2, midpointrounding. toeven); // 3.14
B = system. math. round (n, 2, midpointrounding. awayfromzero); // 3.15
Truncate: essentially removes the decimal part and moves closer to 0. For example, the coordinates of 0.9 and-0.9 are changed to 0.
Ceiling: move closer to the next largest integer. For example, if 0.9 is changed to 1,-0.9 is changed to 0.
With other functions, you must use multiplication/Division fraud to achieve the same effect:
C = system. math. truncate (n * 100)/100; // 3.14
D = system. math. ceiling (n * 100)/100; // 3.15