0

我有一个自定义的网络控件。

循环中的一些代码:

double cellHeight = 12.34;
Label dcell = new Label();
dcell.Style["height"] = cellHeight  + "pt";
dcell.Text = cellHeight;

如果我使用CultureInfo("cs-CZ")

System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("cs-CZ");

渲染后,html出来了

<span style="height:11,75pt">11,75</span>

实际上我所期望的是:

<span style="height:11.75pt">11,75</span> 

height:11,75pt在浏览器中呈现时是完全错误的,实际上浏览器并不11,75pt认为11.75pt.

但是我需要保持基于文化信息显示的文本字段:文本字段显示11,75是正确的。

所以这就是问题所在 - 我该如何解决?

4

1 回答 1

0

您需要正确地将双精度转换为字符串,例如:

dcell.Style["height"] = cellHeight.ToString("F", CultureInfo.CreateSpecificCulture("eu-ES")) + "pt";

或者像这样:

NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
dcell.Style["height"] = cellHeight.ToString(nfi) + "pt";
于 2015-03-11T07:31:03.777 回答