×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    9

    problems with Numers and culture when Convert.ToDouble()

    Im developing an app that will calculate something, im using a texbox to get the data, on my texbox the user only can insert digits and "." for decimals

    When i use double a = Convert.ToDouble(textBox2.Text); i have a lot of trouble, if the user insert 1.5 and the culture of the phone is "en-US" the result is ok 1.5
    but if the culture of the phone is "es-Es" the result is 15, and thats ok for Spain, but this is a problem because on Mexico the culture of the phone is "es-ES" but our numerical sistem is like
    US, we use "." for decimals.

    How can i ignore the culture of the phone? and use "en-US" for my Conver.ToDouble()?

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    296

    Re: problems with Numers and culture when Convert.ToDouble()

    hello aaike64,

    You can use InvariantCulture

    Code:
    double a = Convert.ToDouble(textBox2.Text, System.Globalization.CultureInfo.InvariantCulture)
    Yassine,

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    9

    Re: problems with Numers and culture when Convert.ToDouble()

    hi, Loukt

    I have just read your reply, i solved the problem adding this on my contructor
    Code:
    System.Threading.Thread.CurrentThread.CurrentUICulture =
                new System.Globalization.CultureInfo("en-US");
    System.Threading.Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo("en-US");

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: problems with Numers and culture when Convert.ToDouble()

    You should let the user input data in his/her own culture. Convert (and many other classes) uses the current culture to handle input and output.

Similar Threads

  1. Problems: AudioStream Record and convert pcm to mp3
    By julio_chan in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2010-10-26, 11:19
  2. Numers and CAknIntegerEdwin
    By samosnokia in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-06-02, 08:27
  3. Replies: 6
    Last Post: 2008-03-21, 22:57
  4. Replies: 1
    Last Post: 2008-03-11, 05:32
  5. Convert to mp4
    By panosterz in forum Symbian
    Replies: 0
    Last Post: 2003-06-27, 12:29

Posting Permissions

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