473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't convert string to double!

I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?
Jun 1 '06 #1
10 22137
zelyal wrote:
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?


Almost certainly you're using the wrong CultureInfo. Try specifying
CultureInfo.InvariantCulture to parse in - I suspect it's currently
assuming that "." is a thousands separator rather than a decimal point.

Jon

Jun 1 '06 #2
zelyal,

Works for me. Are you sure it is this line of code?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"zelyal" <ze****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?

Jun 1 '06 #3
culture, perhaps?
Jun 1 '06 #4
What version of the framework are you using? I copied your line of code to a
..Net 2.0 project and it ran without exceptions.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Abnormality is anything but average.

"zelyal" <ze****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?

Jun 1 '06 #5
Specify the number format or culture to use. If you don't do that, you
are using the number format of the default culture.

double v1 = Double.Parse("7200.0", CultureInfo.InvariantCulture);

zelyal wrote:
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?

Jun 1 '06 #6
Verify that the decimal separator is '.' and not something else (like ','
for example). You can use the
System.Globalization.NumberFormatInfo.CurrentInfo. NumberDecimalSeparator
property to check it in code

/claes

"zelyal" <ze****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?

Jun 1 '06 #7
"zelyal" <ze****@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?


Culture, I suspsect. Are you in a country which doesn't use "." as its
decimal separator...?
Jun 1 '06 #8

The problem is in separator. Dot sign leads to error, but with comma sign
all OK.
I tried:
double v1 = Double.Parse ("7200.0", NumberStyles.Float);
but it didn't help. And
v1 = Double.Parse("7200.00", CultureInfo.InvariantCulture);
is gone OK.
Thank to all and specially to Göran Andersson !
Alexey

Jun 2 '06 #9
A clean way to handle this kind of situation is the Double.TryParse().

~ John Fullmer
zelyal wrote:
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?


Jun 2 '06 #10
That prevents the code from causing an exception, but it doesn't solve
the actual problem, which is the number format used to parse the string.
John Fullmer wrote:
A clean way to handle this kind of situation is the Double.TryParse().

~ John Fullmer
zelyal wrote:
I got :
An unhandled exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

at execution of simple line:
double v1 = Double.Parse ("7200.0");

What's wrong?

Jun 2 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cindy liu | last post by:
Hi, In .Net, how to convert a string to a double? Thanks in advance! Cindy
6
by: surrealtrauma | last post by:
i have a trouble about that: i want to ask user to enter the employee data (employee no., name, worked hour, etc.), but i dont know how to sort the data related to a particular employee as a...
2
by: Pascal | last post by:
Why does this not work, and how should i do this convert in stead: string x = double.MinValue.ToString(); double y = Convert.ToDouble(x); i get this exception: An unhandled exception of type...
2
by: paul gao via .NET 247 | last post by:
hi all. In my program I need to convert a double number to stringrepresentation in fraction format and vise versa. For example,convert 0.75 to string "3/4" and convert string "1/2" to 0.5.The class...
0
by: R. John Reed | last post by:
Hi All, I'm am looking to convert a currency string (e.g. "$1,234.56" to a double value). It appears this will work: double val = Convert.ToDouble(Double.Parse­("$123,456.78901",...
2
by: Jason | last post by:
In VB.NET, when I use System.Convert.ToDouble(string Val) to convert a string variable to double variable, I got something interesting: Dim stringVal As String = "101.01" Dim doubleVal As Double...
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
9
by: =?Utf-8?B?Qnlyb24=?= | last post by:
How do you convert a hex string into a double using C# in framework v2.0? I've seen this question answered before, but apparently something has changed in 2.0 that negates the old solution that...
1
by: Bjorn Brox | last post by:
Hi! In germany, norway and France(?) we are using ',' as decimal separator and it always messes up when you convert a double to and from a string where the interface expects double values stored...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.