3

问题存在,razor 将点 (1.11) 的值替换为逗号 (1,11) 的值

它看起来像值:

在此处输入图像描述

但正如网站上显示的那样:

在此处输入图像描述

请告诉我如何使该值达到重点,而不是逗号?

4

2 回答 2

4

似乎您当前的CultureInfo设置为使用逗号作为小数分隔符的一种。

要更正此问题,您可以为整个应用程序强制使用 CultureInfo。在您的web.config添加中:

纠正此问题的一种方法是在您的 web.config 中强制设置文化 infoSet

<globalization uiCulture="en" culture="en-US" />

或者仅为当前请求设置不同的 CultureInfo:

var culture = new Globalization.CultureInfo("ru-RU", false);
culture.NumberFormat.CurrencyDecimalSeparator  = ".";
Threading.Thread.CurrentThread.CurrentCulture = culture;

或者第三种可能性是为方法提供一个IFormatProvider参数ToString

@item.density.ToString(CultureInfo.InvariantCulture)
于 2012-11-26T11:03:24.743 回答
1

ToString returns a human-readable string that is culture-sensitive. For example, for an instance of the Double class whose value is zero, the implementation of Double.ToString might return "0.00" or "0,00" depending on the current UI culture. Your name is Sasha Vasilev, so your UI culture will be ru-RU and decimal separator will be ',' not '.' . You need to do this:

@item.density.ToString(NumberFormatInfo.InvariantInfo)
于 2012-11-26T11:07:04.447 回答