By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,739 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,739 IT Pros & Developers. It's quick & easy.

Problem with Decimal.Parse and CultureInfo

P: n/a
Hello,

I try to convert a volume stored as a string value in an XML file into a
Decimal object. The volume is stored with comma as decimal separator
("210,12") according to french habits. To be independent from the culture of
the current user, I use
decimal.Parse(volume, new System.Globalization.CultureInfo("fr-FR", true));
but this function fails with :
Exception : Input string was not in a correct format.

The O/S is WINDOWS 2000 SERVER SP2 FRENCH, with French-France as current
language in "Regional and Language Options" of the Control Panel. I tried to
change the decimal separator in these settings but no effect.

Moreover, the message of the exception comes in english, instead of french,
as if the framework could not locate the resources for french, and uses its
default (en-US).

The WINDOWS 2000 SERVER is configured as a domain controller, so that the
setup of .NET framework 2.0 partially fails (see
http://support.microsoft.com/kb/315158/) : ASPNET user in not automatically
created; so we had to create a local user manually to run aspnet_wp process :
maybe had we forgotten to grant some right needed to access resources ?

I don't know were to look to solve the problem. Can somebody help me ?

--
Olivier GIL
LAFON SA
May 11 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On May 11, 2:58 pm, Olivier GIL <o...@newsgroup.nospamwrote:
Hello,

I try to convert a volume stored as a string value in an XML file into a
Decimal object. The volume is stored with comma as decimal separator
("210,12") according to french habits. To be independent from the culture of
the current user, I use
decimal.Parse(volume, new System.Globalization.CultureInfo("fr-FR", true));
but this function fails with :
Exception : Input string was not in a correct format.

The O/S is WINDOWS 2000 SERVER SP2 FRENCH, with French-France as current
language in "Regional and Language Options" of the Control Panel. I tried to
change the decimal separator in these settings but no effect.

Moreover, the message of the exception comes in english, instead of french,
as if the framework could not locate the resources for french, and uses its
default (en-US).

The WINDOWS 2000 SERVER is configured as a domain controller, so that the
setup of .NET framework 2.0 partially fails (seehttp://support.microsoft.com/kb/315158/) : ASPNET user in not automatically
created; so we had to create a local user manually to run aspnet_wp process :
maybe had we forgotten to grant some right needed to access resources ?

I don't know were to look to solve the problem. Can somebody help me ?

--
Olivier GIL
LAFON SA
Oliver,

try to test what you get

CultureInfo culture = new CultureInfo("fr-FR");
NumberFormatInfo numInfo = culture.NumberFormat;
Response.Write(numInfo.CurrencyDecimalSeparator);

decimal d = decimal.Parse(s, numInfo);
Response.Write(d.ToString());

May 11 '07 #2

P: n/a
Hi Olivier,

I think you can try setting the "UseUserOverride" to false so as to avoid
the impact from your local operating system's current user locale setting.
e.g.

================
string str = "210,12";

CultureInfo ci = new CultureInfo("fr-FR",false);

Decimal val = Decimal.Parse(str,ci.NumberFormat);
===================

also, from the MSDN document:

#CultureInfo Constructor (Int32, Boolean)
http://msdn2.microsoft.com/en-us/lib...23(VS.71).aspx

it indicate that when you set "UseUserOverride", the current windows locale
setting will override the cultureinfo's setting:
>>>>>>>>>>>>>>>>
If the UseUserOverride property is set to true and the specified culture
identifier matches the culture identifier of the current culture of
Windows, this constructor creates a CultureInfo that uses those overrides,
including user settings for the properties of the DateTimeFormatInfo
instance returned by the DateTimeFormat property, the properties of the
NumberFormatInfo instance returned by the NumberFormat property, and the
properties of the CompareInfo instance returned by the CompareInfo
property. If the user settings are incompatible with the culture associated
with the CultureInfo (for example, if the selected calendar is not one of
the OptionalCalendars), the results of the methods and the values of the
properties are undefined.
<<<<<<<<<<<<<<<<<

So is your test machine's current user locale setting use a number format
which doesn't accept common separate decimal?

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

May 14 '07 #3

P: n/a
Hello,

I've already tried to set UseUserOverride to false, but it has no effect.
Moreover, exception messages come in english instead of french. It looks as
if french culture were not present in the framework.

Where can I check the available cultures of the framework (.NET v.2.0) ?

--
Olivier GIL
LAFON SA
"Steven Cheng[MSFT]" wrote:
Hi Olivier,

I think you can try setting the "UseUserOverride" to false so as to avoid
the impact from your local operating system's current user locale setting.
e.g.

================
string str = "210,12";

CultureInfo ci = new CultureInfo("fr-FR",false);

Decimal val = Decimal.Parse(str,ci.NumberFormat);
===================

also, from the MSDN document:

#CultureInfo Constructor (Int32, Boolean)
http://msdn2.microsoft.com/en-us/lib...23(VS.71).aspx

it indicate that when you set "UseUserOverride", the current windows locale
setting will override the cultureinfo's setting:
>>>>>>>>>>>>>>>
If the UseUserOverride property is set to true and the specified culture
identifier matches the culture identifier of the current culture of
Windows, this constructor creates a CultureInfo that uses those overrides,
including user settings for the properties of the DateTimeFormatInfo
instance returned by the DateTimeFormat property, the properties of the
NumberFormatInfo instance returned by the NumberFormat property, and the
properties of the CompareInfo instance returned by the CompareInfo
property. If the user settings are incompatible with the culture associated
with the CultureInfo (for example, if the selected calendar is not one of
the OptionalCalendars), the results of the methods and the values of the
properties are undefined.
<<<<<<<<<<<<<<<<<

So is your test machine's current user locale setting use a number format
which doesn't accept common separate decimal?

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

May 14 '07 #4

P: n/a
On May 14, 10:04 am, Olivier GIL <o...@newsgroup.nospamwrote:
Hello,

I've already tried to set UseUserOverride to false, but it has no effect.
Moreover, exception messages come in english instead of french. It looks as
if french culture were not present in the framework.
Culture doesn't effect on the errors

Where can I check the available cultures of the framework (.NET v.2.0) ?
// Get and enumerate all cultures.
CultureInfo[] allCultures;
allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo ci in allCultures)
{
Response.Write(ci.Name);
}

May 14 '07 #5

P: n/a
Thanks for your reply Olivier,

That really be unexpected. What's your operating system's version, have you
ever met this problem before or is this the first time you encounter this
problem on that machine? This is likely a machine specific problem, have
you tried testing on some other local boxes to see whether the same problem
happen?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 15 '07 #6

P: n/a
Hi Olivier,

Have you got any progress or new finding? If the problem is specific to a
certain machine, it would be related to the region setting also. Due to the
complexity of such troubleshooting, you can consider contact CSS for
further assistance if this is an urgent issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 18 '07 #7

P: n/a
Hello Steven,

I got the explanation for my problem.

The point is that the regional settings of the O/S are specific to each
user. When I use CultureInfo("fr-FR",true), the culture gets the decimal
separator for the user under which the ASP.NET process runs, i.e.
IWAM_machineName on a w2k domain controller. As the decimal separator was set
to "." at installation time of the O/S, IWAM_machineName user inherits this
default setting (stored I guess in the registry HKEY_USERS/.DEFAULT/Control
Panel/International), and I can't change it any more (except by modifying the
registry).

Moreover, the method CultureInfo.CreateSpecificCulture does not allow to
specify the UseUserOverride parameter, and assumes it as true. So when I use
CreateSpecificCulture("fr"), I inherent user settings to.

Eventually, I set UseUserOverride to false in all my calls to
new CultureInfo( "fr-FR", false ),

and when specific culture from neutral culture was needed, I made :

CultureInfo myCulture = new CultureInfo(
CultureInfo.CreateSpecificCulture("fr").Name, false);

These modifications solved my problem.

--
Olivier GIL
LAFON SA
"Steven Cheng[MSFT]" wrote:
Hi Olivier,

Have you got any progress or new finding? If the problem is specific to a
certain machine, it would be related to the region setting also. Due to the
complexity of such troubleshooting, you can consider contact CSS for
further assistance if this is an urgent issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 22 '07 #8

P: n/a
Thanks for your followup Olivier,

Glad that you've figured out the issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
May 23 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.