0

I have a self defined web control.

Some code in a loop:

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

If I use CultureInfo("cs-CZ")

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

after render, the html came out

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

actually what I expected is:

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

height:11,75pt is totally wrong when rendered in browser, actually the browser does not consider 11,75pt as 11.75pt.

However I need to keep the text field displayed based on culture info: the text field displays 11,75 that is correct.

So this is the problem - how can I fix?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

You need to convert double to string properly, for example:

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

Or like this:

NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
dcell.Style["height"] = cellHeight.ToString(nfi) + "pt";
ttaaoossuuuu
  • 7,786
  • 3
  • 28
  • 58
  • one more: eg . double widthd=59.25; dcell.Width= new Unit(widthd, UnitType.Point) ; then the rendered html is also width 59,25pt ,how to avoid it ,seems Unit classes rendered the value by culture info.but actually it no need. – user1614536 Mar 19 '15 at 03:21