Accumulate by bit [C #]-rounding (function)

Source: Internet
Author: User

Effect:

Description: enter a decimal number and the number of digits to be retained,

Event: click button

Code:

 1   Public   Static   Double Round ( Double D, Int  I)  2   {  3               If (D> = 0  )  4  {  5 D + = 5 * Math. Pow ( 10 ,-(I + 1 )); //  Evaluate the specified power of a specified number of times  6   }  7               Else  8   {  9 D + = 5 * Math. Pow ( 10 ,-(I + 1  ));  10   }  11               String STR = D. tostring ();  12               String [] STRs = Str. Split ( '  .  '  );  13               Int Idot = Str. indexof ( '  .  '  );  14               String Prestr = STRs [ 0  ];  15               String Poststr = STRs [ 1  ];  16               If (Poststr. length> I)  17  {  18 Poststr = Str. substring (idot + 1 , I ); //  Number of digits required for Truncation  19   }  20               If (Poststr. Length <= 2  )  21   {  22 Poststr = poststr +"  0  "  ;  23   }  24               String Strd = prestr + "  .  " + Poststr;  25 D = Double . Parse (strd ); //  Converts a string to a double-precision real number. 26               Return  D;  27   }  28   29           Private   Void Button#click ( Object  Sender, eventargs E)  30   {  31 Textbox3.text =Convert. tostring (math. Round (convert. todouble (textbox1.text. Trim (), convert. toint16 (textbox2.text. Trim ())));  32 }

 

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.