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"));
}
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)
Ste*_*fan 56
使用"Nx"表示x十进制数字.
public void DisplayNDecimal(double dbValue, int nDecimal)
{
Console.WriteLine(dbValue.ToString("N" + nDecimal));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
44126 次 |
最近记录: |