I would use this:
public string DisplayNDecimal(double dbValue, int nDecimal)
{
string decimalPoints = "0";
if (nDecimal > 0)
{
decimalPoints += ".";
for (int i = 0; i < nDecimal; i++)
decimalPoints += "0";
}
return dbValue.ToString(decimalPoints);
}
:)
Here is it with StringBuilder
(though probably not more efficient and definitely would require more resources)
public string DisplayNDecimal(double dbValue, int nDecimal)
{
StringBuilder decimalPoints = new StringBuilder("0");
if (nDecimal > 0)
{
decimalPoints.Append(".");
for (int i = 0; i < nDecimal; i++)
decimalPoints.Append("0");
}
return dbValue.ToString(decimalPoints.ToString());
}