<%= Math.Round(netValue)%>
它的输出示例可能是-1243313
如何确保它格式化为美元货币(包括'$'、正确的逗号等)?
<%=string.Format(CultureInfo.GetCultureInfo(1033), "{0:C}", Math.Round(netValue)) %>
(1033是'英语-美国'文化的区域标识符)
<%= Math.Round(netValue).ToString("C") %>
CultureInfo usaCulture = new CultureInfo("en-US");
<%= Math.Round(netValue).ToString("C", usaCulture) %>
format
的货币代码C
:
decimal moneyvalue = 1921.39;
string output = String.Format("Order Total: {0:C}", moneyvalue);
Console.WriteLine(output);
编辑:如果国际化是一个问题,您可能也想看一下本地化。