这似乎是一个非常愚蠢的问题,但我还没有设法解决它。这是代码:
private string[] ConvertToCurrency(string[] costs)
{
int count = costs.Length;
for (int i = 0; i < count - 1; i++)
{
costs[i] = String.Format("{0:C}", costs[i]);
}
return costs;
}
我希望输出应该是我存储在我的字符串数组中的数字将被格式化为货币,但当它们从另一端出来时它们完全没有变化。
我不知道为什么会这样,并尝试了一些其他方法来格式化它,但没有成功。
最佳答案
您应该这样做,{0:C}
用于货币格式,它将应用于数值。
costs[i] = String.Format("{0:C}", Convert.ToDecimal(costs[i]));
关于c# - String.Format 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13191619/