CultureInfo and Decimal point.

  • Thread starter Thread starter Hector
  • Start date Start date
H

Hector

Hi,

My application supports different languages, and i have a problem with the
decimals:
In this application, i receive datas like "10.528".
When i use CurrentCulture = "en-US", no problem.
But with "fr-FR" for example, there's a bug.

Of course, one way to solve this problem is to test if the current language
is "fr-FR" and then make a Replace(",",".").

But i guess there's should be a better way, no ?

Thanks.
 

Hey Hector.

Here's a small example of one way to solve the problem:

//
// Assume the application is running under
// the French language
//
Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo("fr-FR");
//
// Get a string value with the number
//
string val = "10.90";
//
// Parse the string as a decimal using the
// english (US) culture
//
Decimal data = Decimal.Parse(val,
new System.Globalization.CultureInfo("en-US"));
//
// Write the value to screen
// Should be 10,90
//
Console.WriteLine(data);
 
Hi Hector,

I agree with David that you can specify the en-US culture info as format
provider. However, in my opinion, if the machine's locale setting has been
set to fr-FR, it will be better for us to observe the machine setting,
since the user to this machine might be used to take comma as decimal point.

If there is anything unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================
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.)
 
Hi Hector,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

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

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

Back
Top