`Double.ToString` with N number of decimal places [duplicate]
I know that if we want to display a double
as a two decimal digit, one would just have to use
public void DisplayTwoDecimal(double dbValue)
{
Console.WriteLine(dbValue.ToString("0.00"));
}
But how to extend this to N
decimal places, where N
is determined by the user?
public void DisplayNDecimal(double dbValue, int nDecimal)
{
// how to display
}
Use "Nx" for x decimal digits.
public void DisplayNDecimal(double dbValue, int nDecimal)
{
Console.WriteLine(dbValue.ToString("N" + nDecimal));
}