Answer the question
In order to leave comments, you need to log in
What's the easiest way to round three numbers in a row without using iteration in C#?
Now it looks like this:
double a, b, c;
Console.WriteLine(Math.Round(a, 2)+" "+ Math.Round(b, 2)+" "+Math.Round(c, 2));
Answer the question
In order to leave comments, you need to log in
Without a loop, just as you said (with options in the form of creating temporary variables with the results). Otherwise you need a cycle. But the cycle can be inside some function, for example, in string.Join. And then, you still have to manually place the data in the array.
double a = 10.123, b = 20.234, c = 30.345;
Console.WriteLine(Math.Round(a, 2) + " " + Math.Round(b, 2) + " " + Math.Round(c, 2));
Console.WriteLine(string.Join(" ", new []{a, b, c}.Select(x => x.ToString("F2"))));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question