After-school assignment 06--The number of decimals after the precise judgment and output

Source: Internet
Author: User

            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

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.