Results 1 to 5 of 5

Thread: Convert a string to form Double in .NET

  1. #1
    Join Date
    Jul 2006
    Posts
    339

    Convert a string to form Double in .NET

    Hi friends, I am with this terrible mess.At first glance seem a trivial problem, but its solution is not at all. I need to convert a string type double that takes the form \ d +. \ D + (2,413, 321.32, 33.33). Try several ways: CDbl (), Convert.ToDouble (), Double.Parse () and each of them always get the same result:the chain becomes, but lost decimal places, that is, I always transforms into a whole number. For example, the 2413 becomes 2413, then 32,132 is the 321.32 and with all the numbers. This does not happen to me if instead of separating the decimals with one character ','. kids with ','. I guess the problem must come a point format of the chain.

    Replacing the "." by "," in each chain me works well,but i can not do that because i am doing an analyzer of mathematical expressions and the "character" is reserved for the separation of the argument when the function is called.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Convert a string to form Double in .NET

    Before making the conversion from string to double, I recommend that you change the channel points by coma.

    string str = "10.5";
    cadena.Replace (".",",");
    Convert.ToDouble (string);

    so you give a result.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Convert a string to form Double in .NET

    Replacing the "." by "," in each chain me works well,but i can not do that because i am doing an analyzer of mathematical expressions and the "character" is reserved for the separation of the argument when the function is called.

    If I was too reserved to separate the arguments then as the analyzer to differentiate the two following cases ?

    func (1,234,12,456) ->

    A. func(1,234 , 123,465)
    B. func(1 , 234,123,465)

    Or something like that ... l He uses another character to separate the arguments, or not let thousands of tabs in your equation, or use the ".." Or perhaps I'm talking about something else

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Convert a string to form Double in .NET

    Your problem is culturalization ,revises something like this

    NumberFormatInfo NFI = new NumberFormatInfo ();
    nfi.NumberGroupSeparator = "";
    double d = double.Parse (s, NFI);
    Console.WriteLine (d);

  5. #5
    Join Date
    Jul 2006
    Posts
    339

    Re: Convert a string to form Double in .NET

    Indeed it was a problem of culturalization, because I could fix it. Thank you. Con With respect to your question PraetorC not let thousands separators, when it encounters the character '. " is interpreted as decimal separator only.

Similar Threads

  1. Convert string into int in C
    By screwball in forum Software Development
    Replies: 4
    Last Post: 22-12-2011, 08:47 PM
  2. Convert XML string into DOM
    By GreatThinker in forum Software Development
    Replies: 6
    Last Post: 22-07-2010, 09:48 AM
  3. How to convert string into int in Java
    By Zool in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 12:41 PM
  4. How to Convert a String to GUID
    By shakira in forum Software Development
    Replies: 5
    Last Post: 07-07-2009, 11:42 AM
  5. How to convert string to int
    By Zavier in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 06:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,044,949.82271 seconds with 17 queries