0

I want to have the user say how many decimal points they want to display, I am trying to use format specifiers like {0:F2} but when I try something like

Console.WriteLine("{0} added to {1} is {2:F{3}}", Num1, Num2, Answer, DP);

it doesn't work, how do I do it?

Kronos
  • 126
  • 8

1 Answers1

1

Try .ToString(string Format):

Console.WriteLine("{0} added to {1} is {2}", Num1, Num2, Answer.ToString("F" + DP));

This will pass "F" + DP for the format provider. So, if DP = 2, then it would write the Answer as Answer.ToString("F2") (2 decimal places).

dvo
  • 2,113
  • 1
  • 8
  • 19