dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Decimal.Parse and culture

  1. #1
    Join Date
    Jul 2010
    Posts
    10

    Decimal.Parse and culture

    Hi,

    I have a decimal value stored in my database and it is being displayed via my client. When the client was installed on a computer with the culture set to Polish, it introduced some errors.

    For example, the value is 50,000.10. The client displays this value in polish as 50.000,10. As you can see the points and commas are switched. When they come to save this information, in code I am using the following, which fails.

    this._myValue = decimal.Parse(this.field1.Text, NumberStyles.Currency);

    I have tried using the IFormatProvider overload for Decimal.Parse like this but with no luck;

    this._myValue = decimal.Parse(this.field1.Text, NumberStyles.Currency, CultureInfo.InvariantCulture);

    I have also tried a new "en-GB" just to see, and i keep getting "Input was not in the correct format". My question is, how do I essentially convert a polish formatted string value in to a Decimal field?

    Thanks for any help you could give,

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Decimal.Parse and culture

    I think that followign should be sufficient
    Code:
    this._myValue = decimal.Parse(this.field1.Text, NumberStyles.Currency, new CultureInfo("pl"));
    or, because you cannot know which culture is set on the machine running the application
    Code:
    this._myValue = decimal.Parse(this.field1.Text, NumberStyles.Currency, CultureInfo.CurrentUICulture);
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)