M $ is always a leader. Math. Round () in C # seems to be not so useful in round-robin calculation. It can be said that it is "five homes and six in ~~~ I didn't know this at the beginning, and the calculation results were always incorrect. Later, I followedProgramThis method fooled me. No way. Since it is so difficult to use or have no Chinese characteristics, you can only create some Chinese characteristics on your own. Override round ():
Public Static Double Round ( Double D, Int I)
{
If (D > = 0 )
{
D+ = 5 *Math. Pow (10,-(I+ 1));
}
Else
{< br> 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 + " . " + Poststr;
D = Double. parse (strd );
Return D;
}
Parameter: D indicates the number to be rounded to, And I indicates the number of decimal places to be retained.
Initially, the results are not bad. I thought about all the questions in the book. OK! That's all. Don't affect the accuracy of GM.
Finally, let's take an ion and describe the principle:
If you want to round 1.4 and 1.5 to an integer, add 0.5 first, and then the string of digits before the decimal point is OK. We can see that 1.4 + 0.5 = 1.9 = get 1; 1.5 + 0.5 = 2.0 = Get 2. This is a perfect idea!
PS: It's a pity that I didn't come up with a good idea! Thanks to the unsung hero on the Internet ~~~ It's a little comforting for me to make good ideas and implement them into action...