Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-11-2008
Member
 
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.
Reply With Quote
  #2  
Old 17-11-2008
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #3  
Old 17-11-2008
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: Convert a string to form Double in .NET

Quote:
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
Reply With Quote
  #4  
Old 17-11-2008
Member
 
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);
Reply With Quote
  #5  
Old 17-11-2008
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Convert a string to form Double in .NET"
Thread Thread Starter Forum Replies Last Post
Convert string into int in C screwball Software Development 4 22-12-2011 08:47 PM
Convert XML string into DOM GreatThinker Software Development 6 22-07-2010 09:48 AM
How to convert string into int in Java Zool Software Development 3 09-11-2009 12:41 PM
How to Convert a String to GUID shakira Software Development 5 07-07-2009 11:42 AM
How to convert string to int Zavier Software Development 3 04-06-2009 06:24 PM


All times are GMT +5.5. The time now is 09:04 PM.