SharePoint regional settings double value bug

Here is an interesting one…

I had to set the regional settings of my SharePoint site to Hungarian, so the DateTime fields get localized properly. This has been discussed previously here.

However, I started experiencing problems with the double values. Explanation by example:
(myField is of type SPFieldNumber)


double myDouble = 123.45;
myField.DefaultValue = myDouble.ToString();

Basically, I am trying to assign the value of a type double variable as the default value of my SharePoint field (which I am about to render).

At this point, when I check (using Quick Watch in Visual Studio) the value of myField.DefaultValue it shows 123,45 (which is ok, for the localization I am using). However, myField.DefaultValueTyped shows 12345. Looks like SharePoint is ignoring the fact that the site is localized and does not consider ‘,’ to be in the role of a ‘.’

The solution I came up with is:
double myDouble = 123.45;
myField.DefaultValue = myDouble.ToString(CultureInfo.InvariantCulture);

Perhaps it is not the best, but at least the output now is:
myField.DefaultValue = “123,45”
myField.DefaultValueTyped = 123.45

Which is what is expected! Let me know if you know of a better way!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: