|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
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
| |||
| |||
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
| |||
| |||
Re: Convert a string to form Double in .NET Quote:
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
| |||
| |||
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
| |||
| |||
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. |
![]() |
|
Tags: convert, net, string |
Thread Tools | Search this Thread |
|
![]() | ||||
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 |