Description:
Only a maximum of six decimal places can be rounded in. Note that you can take the initiative to go to 0 at the end of the decimal point (for example, 1.20f is considered as: 1.2f ), if the input decimal point is 2.0f, 0 is returned as an integer;
Resolved issues:
Rounding the mathf. Round Function in the unity3d holy bookReturns the nearest integer rounded to the floating point F.Assume that the number ends with. 5, so it is in the middle of two integers,Whether it is an even number or an odd number, an even number is returned..
Code: [C #, unity3d Holy Book]
Float myround (float f) {string S = f. tostring (); string [] S0 = S. split (New char [] {'. '}); If (s0.length = 1) {print ("it is a integer"); Return 0;} If (s0.length! = 2) {print ("Something is wrong"); Return 0;} If (S0 [1]. length = 1) // If (Int. parse (S0 [1] [0]. tostring ()> = 5) return mathf. floortoint (f) + 1; elsereturn mathf. floortoint (f);} float power = 10; for (INT I = 2; I <S0 [1]. length; I ++) // S0 [1]. length indicates the number of digits in the decimal part {power * = 10;} f * = power; F = mathf. floortoint (f); If (Int. parse (S0 [1] [S0 [1]. length-1]. tostring ()> = 5) F + = 1; F/= power; return F ;}