/// <summary>///formatting Decimal numbers for efficient calculation/// </summary>/// <param name= "ori" ></param>/// <returns></returns>/// <remarks></remarks> Public Static decimalFormatdecimal (decimalOri) { if(Ori = =0) { return 0; } decimalnum =The Ori; decimalresult =0m; intZoome =1; //Number less than 100, the number is magnified by 10, until the number is greater than or equal to while(Num < -) {num= num *Ten; Zoome= Zoome *Ten; } intInt1 =Math.floor (num); decimalD1 = Math.floor (num) +0.5; //four six in//5 See Mantissa and parity if(Num >D1) { //If there is a mantissa after 5, carryresult = Int1 +1; } Else if(num = =D1) { //look at the previous one even unchanged, odd +1 if(Int1%2==0) {result=int1; } Else{result= Int1 +1; } } Else { //integerresult =int1; } //effective numbers are reduced to the original order of magnituderesult = result/zoome; returnresult;}/// <summary>///format string Displays Decimal digits/// </summary>/// <param name= "ori" ></param>/// <returns></returns>/// <remarks></remarks> Public Static stringShowdecimal (decimalOri) { if(Ori = =0) { return "0"; } //first get formatted data, valid numbersOri =Formatdecimal (ORI); stringStrnum =""; decimalnum =The Ori; //determine if 3 digits and 3 digits are directly taken as integral parts if(Num >= -) {Strnum=Num. ToString (); } Else if(Num >0) { //less than three digits, which involves taking a decimal point strings =Num. ToString (); //no decimal point, first number of decimal places if(S.contains (".") ) {s= S +"xx"; } Else{s= S +". XX"; } //traversing 3-bit valid digits Char[] Array =S.tochararray (); intStart =0; for(inti =0; I <= array. Length-1; i++) { if(Start = =3) { Break;//todo:might not being correct. Was:exit for } if(Array[i] = =".") {Strnum= Strnum +"."; } Else { intt =int. Parse (Array[i]); if(T >0) {Start= Start +1; Strnum= Strnum +T; } Else if(T = =0) { if(Start >0) {Start= Start +1; Strnum= Strnum +T; } Else{strnum= Strnum +T; } } } } } returnStrnum;}
Algorithm: Four six into 50% pairs, reserved three digits of valid digits