Problem with Decimal.Parse and CultureInfo

G

Guest

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 ?
 
G

Guest

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 ?

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());
 
S

Steven Cheng[MSFT]

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/library/aa328523(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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



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

Guest

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) ?
 
G

Guest

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);
}
 
S

Steven Cheng[MSFT]

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.
 
S

Steven Cheng[MSFT]

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.
 
G

Guest

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.
 
S

Steven Cheng[MSFT]

Thanks for your followup Olivier,

Glad that you've figured out the issue.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top