Task: Change the program so that the number, E is displayed on the screen with an accuracy of up to 6 decimal places.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { static void Main() { double x = Math.E; Console.WriteLine("E={0:##.######}", x); Console.WriteLine("E={0:.####}", x); } } } 

I have an idea what to do

 Console.WriteLine("E={0:##.######}", x); Console.WriteLine("E={0:.######}", x); 

But it seems to me that this is not what I mean therefore I am writing to the forum

  • @Zadohlik, According to the rules of the forum, questions should not be limited to solving or completing student assignments. Please clarify what you have done yourself and what did not work out. - Nofate
  • I have an idea what to do with Console.WriteLine ("E = {0: ##. ######}", x); Console.WriteLine ("E = {0:. ######}", x); But it seems to me that this is not what I mean therefore I am writing to the forum - shell_bug
  • one
    > But it seems to me that this is not what it means, maybe you should clarify what exactly is meant by the one who gave you this task? In my humble opinion, your answer fully satisfies the condition of the problem - DreamChild
  • That's the whole point is that clarify will not work. I study "remotely" on microsoft academy. But actually if you 're interested in a link to the lecture onedrive.live.com/… - shell_bug

1 answer 1

In general, yes, you solved the problem correctly. It is unlikely that it meant something else. A little more:

 double x = Math.E; Console.WriteLine("E={0:##.######}", x); // не более шести знаков Console.WriteLine("E={0:0.000000}", x); // ровно шесть знаков Console.WriteLine("E={0:F6}", x); // число с плавающей точкой и 6 знаков после запятой 

Read more about formatting here and here.

  • DreamChild thank you very much. I wrote on a bunch of forums, answered only here)) But even so, it’s not clear why giving such an unequivocal statement of the task if the decision is “not a solution”. Well, this question is probably worth asking those who compose tasks and lectures. Thank you - shell_bug