Console.Write ("Enter the decimal you want to be precise:"); String stra = Console.ReadLine (); Console.Write ("You want to be accurate to several decimals:"); int k = Int. Parse (Console.ReadLine ()); Double n = convert.todouble (stra); int i = Stra.indexof ("."); /determines the decimal index position of string StrB = string. Empty; try {StrB = stra.substring (i + k + 1, 1);//intercept the exact decimal after the next bit int m = Int. Parse (StrB); String strc = stra.substring (i + 1, k);//intercept the number of decimal parts to retain double j = Math.floor (n); Stra = Convert.ToString (j);//extract its integer part stra = Stra + "." + strc;//integer plus to exact fractional fraction double q = conve Rt. ToDouble (Stra); Console.Write ("The exact number is:"); if (M >= 5) Console.Write (q + Math.pow (0.1, k));//five into else Console. Write (q); } catch {Console.WriteLine ("Exact decimal places are larger than the number of decimals you have entered!"); } console.readline ();
After-school assignment 06--The number of decimals after the precise judgment and output