// 1.
System. globalization. numberformatinfo provider = new system. globalization. numberformatinfo (); provider. numberdecimaldigits = intdeclength; // number of decimal places to be set double strcashamt=convert.todouble(this.txt cashamt. text); // convert the value of the Controller to doublethis.txt cashamt. TEXT = strcashamt. tostring ("N", provider); // use the tostring function to format the number of decimal places. // 2. N digits are retained. decimal d = decimal. round (decimal. parse ("0.55555"), 2); // 3. N digits are rounded to math. round (0.55555, 2) // 4, retain N digits rounded to double dbdata = 0.55555; string str1 = dbdata. tostring ("F2"); // FN retains N bits, rounded to/5. keep n digits rounded to string result = string. format ("{0: N2}", 0.55555); // two-digit string result = string. format ("{0: N3}", 0.55555); // 3 bits // 6. keep n digits rounded to (good) double S = 0.55555; Result = S. tostring ("#0.00"); // a few digits after a few zeros are retained. // The solution for displaying the number of decimal places and percent signs in C # is as follows: // 1. Use the numberformatinfo class to solve the problem: system. globalization. numberformatinfo provider = new system. globalization. numberformatinfo (); provider. percentdecimaldigits = 2; // number of digits to the decimal point. provider. percentpositivepattern = 2; // Where is the percent sign. double result = (double) 1/3; // be sure to use the double type. response. write (result. tostring ("P", provider); // 2. Use the tostring method.: Public String getrate (double hcount, double task) {string rvalue; string temp = ""; if (task = 0) {task = 1 ;} double DB = (hcount/task) * 100; If (hcount> = task) {rvalue = "100%";} else {rvalue = dB. tostring ("#0. #0 ") +" % ";} return rvalue;} string str1 = string. format ("{0: N1}", 56789); // result: 56,789.0 string str2 = string. format ("{0: N2}", 56789); // result: 56,789.00 string str3 = string. format ("{0: N3}", 56789); // result: 56,789.000 string str8 = string. format ("{0: F1}", 56789); // result: 56789.0 string str9 = string. format ("{0: F2}", 56789); // result: 56789.00 string str11 = (56789/100 .0 ). tostring ("#. # "); // result: 567.89 string str12 = (56789/100 ). tostring ("#. # "); // result: 567