473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 15011
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.