### 如何格式化双倍货币四舍五入到最接近的美元？

``````double numba = 5212.6312
String.Format("{0:C}", Convert.ToInt32(numba) )
``````

``````\$5,213.00
``````

#### 6 个答案:

``````decimal numba = 5212.6312M;
string s = numba.ToString("C0");
``````

``````String.Format("{0:C0}", Convert.ToInt32(numba))
``````

`C`后面的数字指定要包含的小数位数。

``````Console.WriteLine(numba.ToString("C0"));
``````

``````Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalDigits = 0;
``````

``````String.Format("{0:C0}", numba)
``````

`````` decimal value = 0.00M;
value = Convert.ToDecimal(12345.12345);
Console.WriteLine(".ToString(\"C\") Formates With Currency \$ Sign");
Console.WriteLine(value.ToString("C"));
//OutPut : \$12345.12
Console.WriteLine(value.ToString("C1"));
//OutPut : \$12345.1
Console.WriteLine(value.ToString("C2"));
//OutPut : \$12345.12
Console.WriteLine(value.ToString("C3"));
//OutPut : \$12345.123
Console.WriteLine(value.ToString("C4"));
//OutPut : \$12345.1235
Console.WriteLine(value.ToString("C5"));
//OutPut : \$12345.12345
Console.WriteLine(value.ToString("C6"));
//OutPut : \$12345.123450
``````