View Single Post
Old 08-17-2011, 03:18 AM   #2
t1tg0bvcn
 
Posts: n/a
Default

C # there is no rounding function, programming language functions are not rounded, because the rounding algorithm is unscientific,belstaff jackets, is the internationally accepted Banker rounding

Bankers rounding (banker's rounding) algorithm, that is, six- four homes Ruwu get even. In fact this is the standard IEEE rounding provisions. Meet the IEEE standard so all languages should be using this algorithm

Math.Round method is the default rounding Banker

in . NET 2.0 There are several ways in Math.Round overload
Math.Round (Decimal, MidpointRounding)
Math.Round (Double, MidpointRounding)
Math.Round (Decimal, Int32, MidpointRounding)
Math.Round (Double, Int32, MidpointRounding)

the small rounding to the specified precision. MidpointRounding parameter, specify a value when the number exactly in the middle of the other two how to round this value is the parameter



MidpointRounding enumeration has two members of this enumeration, MSDN described is:
AwayFromZero When a number is the median of the other two numbers, the will of its two values rounded to the smaller absolute value.
ToEven When a number is the median of the other when the two figures,belstaff online, will be rounded to the nearest even number.

note! Note on the MidpointRounding.AwayFromZero here is wrong! Rounding the actual absolute values for the two larger values. However, in the example of MSDN is correct, the English text is a description of it is rounded toward the nearest number that is away from zero.

Therefore,belstaff blouson, to achieve the rounding function, for positive numbers,outlet belstaff, you can add a MidpointRounding.AwayFromZero parameters specify when a number is the median of the other two numbers when rounded to two values in the larger absolute value, for example:

Math.Round (3.45, 2, MidpointRounding.AwayFromZero)

However, the above method for the negative of the

therefore not need to write a function to handle
the first function:
double Round (double value,belstaff panther jacket, int decimals)
{
if (value = 0)
{
d + = 5 * Math.Pow (10, - (i + 1));
}
else
{
d + = -5 * Math.Pow (10, - (i + 1));
}
string str = d.ToString ();
string [] strs = str.Split ('.');
int idot = str.IndexOf ('.');
string prestr = strs [0 ];
string poststr = strs [1];
if (poststr.Length> i)
{
poststr = str.Substring (idot + 1, i);
}
string strd = prestr + \ number; i want to keep that number after the decimal point.
The second method is
which positive and negative numbers are rounded, the first rounding is positive,belstaff leather jacket, negative, six into the five homes.
Note: I personally believe the first method for dealing with currency, while the second method is suitable for the display of statistics.
  Reply With Quote

Sponsored Links