Algorithm: Four six into 50% pairs, reserved three digits of valid digits

Source: Internet
Author: User

/// <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.