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.

No comments:

Post a Comment

About Cullen

My photo
Christian, Father, Software Developer/Architect who enjoys technology and using it to make people's lives easier!

Followers