Beware the decimal separator

code, silverlight — Szili @ 3:18 pm

The clash between decimal separators, double values and application culture already made Point type a victim. Today I found abound another one..

I had an iframe positioned above my silverlight control. Its dimensions was controlled from C# managed code (with the use of System.Windows.Browser library).
Or at least it should have been.

ERROR:

No matter I gave the right double values to set the iframe’s width, it just didn’t changed:

Iframe.SetStyleAttribute("width", value.ToString() + "px");

SOLUTION:

After a few rounds of debugging I found the solution. The problem was caused by the decimal separator being a comma instead of a point.

The fix is the same as with the Point type:

Iframe.SetStyleAttribute("width", value.ToString(System.Globalization.CultureInfo.InvariantCulture) + “px”);

2 Comments »

  1. […] Beware the decimal separator Post a comment | Trackback URI […]

    Pingback by Silverlight Emotional Handbook < Szili — January 31, 2008 @ 3:20 pm
  2. I did feel the pain last week: I had to implement an AWK script which handles well the input of a 4 GB file with mixed thousand and decimal separator, and handle well the output.

    If you look up printf() in AWK you will find, that there is a ‘ option to it which handles the thousand separators. But I just can’t get it working for me: the escaping should have been ‘”‘”‘ and it had thrown an error all the time. So after a while I had implemented a TSEP function instead. And my hair went grey.

    Comment by Zsoltik@ — September 19, 2008 @ 8:29 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2010 Szili | powered by WordPress with Barecity