profile for Cullen Tsering at Stack Overflow, Q&A for professional and enthusiast programmers

Sunday, April 17, 2011

A mystery solved

Today, I was trying to solve a problem where on our French site, a specification number (which is a decimal number) of the same product  was toggling between 1.3 and 1,3 intermittently.  It should be 1,3 for French.  It turned out the problem was in two folds.


First of all, the following code is being used to convert decimal to string:
//specNumber = 1.3;
specNumber.ToString();


Secondly, the app is running on two load balanced servers.  One server's region and language is set up as:

 while the other is set up as below:

That explains why the value is appearing as 1.3 or 1,3 intermittently.


To address this problem, we need to fix it in code.  When the site is being browsed in French we'll use:

   var fr = CultureInfo.CreateSpecificCulture("fr-CA");
   specNumber.ToString(fr.NumberFormat);

That way, the code is not dependent on the server region and language settings.

0 comments:

Post a Comment

About Cullen

Cullen has been coding since 1991. He has been a Sr. Software Engineer/Architect for 11 years and counting. He enjoys coding for work as well as for fun. He loves learning from anyone and delights in sharing the little knowledge he possesses.

Followers