473,408 Members | 1,955 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,408 software developers and data experts.

converting from string to float problem

ool
Hello,

How I can convert value from string to double.

When I do this in that way:

String sParam="150.00";
double dbValue= Convert.ToDouble(szParam);

I get System.FormatEcxeption

Thomas

Nov 15 '05 #1
3 1531
Thomas,

You might find the either Double.Parse or Double.TryParse to be a bit more
useful than Convert.ToDouble.

HTH,
Nicole
"ool" <so***@no.spam> wrote in message
news:bk**********@atlantis.news.tpi.pl...
Hello,

How I can convert value from string to double.

When I do this in that way:

String sParam="150.00";
double dbValue= Convert.ToDouble(szParam);

I get System.FormatEcxeption

Thomas

Nov 15 '05 #2
Hi Thomas,

"ool" <so***@no.spam> wrote in message
news:bk**********@atlantis.news.tpi.pl...
Hello,

How I can convert value from string to double.

When I do this in that way:

String sParam="150.00";
double dbValue= Convert.ToDouble(szParam);

I get System.FormatEcxeption


A hunch.

I note that your post seems to originate from Poland, yes? According to
Windows, the Polish culture uses a comma to seperate whole part from decimal
part. Assuming the number you are trying to parse follows the English (U.S.)
format, you could create a CultureInfo object and pass it as the second
(IFormatProvider) parameter to the Convert.ToDouble method.

System.Globalization.CultureInfo enUSCulture =
new System.Globalization.CultureInfo("en-US");

String sParam = "150.00";
double dbValue = Convert.ToDouble(szParam, enUSCulture);

Regards,
Dan
Nov 15 '05 #3
ool <so***@no.spam> wrote:
How I can convert value from string to double.

When I do this in that way:

String sParam="150.00";
double dbValue= Convert.ToDouble(szParam);
I presume your actual code has the same variable name in both places.
I get System.FormatEcxeption


My guess is that you're in a culture where the decimal point is a comma
rather than a dot. Try

double dbValue = Convert.ToDouble (szParam,
CultureInfo.InvariantCulture);

(with a using System.Globalization; statement at the top of your code).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

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

Similar topics

2
by: Ikot | last post by:
Hello, I am stuck with a problem, might be very trivial, to ask here, but dont find a way out. I read a string like 12345.678 from a text file, which will be string for me, but how do I convert it...
15
by: Bushido Hacks | last post by:
Hey c.l.c++ and/or c.g.a.opengl posters, How do I convert a hexidecimal string, traditionally used for defining colors with HTML, into a floating point array? In other words, how do I convert...
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
3
by: Jim Langston | last post by:
I have a CSkill class which is rather complex as it is recursive. That is: class CSkill { public: CSkill( std::string Name, float Value ): Name_( Name ), Value_( Value ) {}; void Update(...
3
by: dean.elwood | last post by:
Hi guys, My first post here and I'm a pascal coder doing his best to move to C/C++ so please go easy on me ;) I'm using the MySQL C API to pull some values from a DB. One of the fields is a...
3
by: pipe.jack | last post by:
I'm trying to convert string to float and my float after conversion is 0 (zero). Here is my code: $c = $currencies->format($cart->show_total()); echo gettype($c); echo (float)$c; $c = 39.59...
12
by: joestevens232 | last post by:
Okay, Im having some problems with my code. Im trying to use the <cstdlib> library and im trying to convert string data at each whitespace slot. I think if you see my code you'll get what im trying...
10
by: Hank Stalica | last post by:
I'm having this weird problem where my code does the following conversion from string to float: 27000000.0 -27000000.00 2973999.99 -29740000.00 2989999.13 -2989999.25 The number on the left...
7
by: DirtyRasa | last post by:
Here is what my professor told me to to. Write a function that converts a string to a float and returns a float. Test your function by entering f4 and with 4f. Both should say Data entered was...
7
by: ma740988 | last post by:
Consider the equation (flight dynamics stuff): Yaw (Degrees) = Azimuth Angle(Radians) * 180 (Degrees) / 3.1415926535897932384626433832795 (Radians) There's a valid reason to use single...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.