473,473 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with Decimal.Parse and CultureInfo

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
8 15020
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: GP | last post by:
Decimal.Parse("100,5") returns 1005 when it should throw an InvalidFormatException. The locale is US therefore the "," is a thousand separator. Even if the parser confused it for the decimal...
2
by: probashi | last post by:
Hi, I am trying to the following: String s = "( 54.05)"; decimal d = decimal.Parse(s); when s = "( 54.05)" I what the value -54.05 and s = " 54.05" I what the value 54.05
3
by: Agnes | last post by:
What value will be return Decimal.parse(Me.txtTest.text) ???? It seems doesn't return False or True, so. what will be returned ? Thanks
3
by: Stefan Richter | last post by:
Following problem: On a german computer system I am developing a program for international computer systems, and I want my programm always to run in the same way. There's a difference in...
8
by: G.Ashok | last post by:
Hi, I have created CultureInfo object and specified required digit grouping in it. The one of the overloaded ToString methods of Decimal type has parameters to format the value with required...
1
by: Mythran | last post by:
Dim value As Decimal = 1234.56 Dim format As String = _ "Positive $#,##0.00;Negative $#,##0.00;" Dim s As String = value.ToString(format) Dim d As Decimal = Decimal.Parse(s) The last line...
4
by: leej | last post by:
Im hoping someone can help me to work out where/what Im missing here. Ive a line in a moderately sized program decimal d1 = Decimal.Parse("0.1"); When I check the result in Visual Studio or...
3
by: Andrew Wrigley | last post by:
Hi, I have a string: "100.00" ....that I want to parse into a decimal. So: decimal d = decimal.Parse("100.00", System.Globalization.NumberStyles.Any) On my dev machine (United Kingdom),...
8
by: Rico | last post by:
Hello Everyone, I observed something strange in some quick testing code: void Button1Click(object sender, System.EventArgs e) { CultureInfo culture = new CultureInfo("th-TH", false); ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.