473,699 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Double conversion problem

Hi there,

I'm having a weird situation when converting strings to double.
Normally, the following code would work right?

double MyDouble = double.Parse("2 0.50"); // Error at runtime

Well, it gives me an error at run time, telling me that the format of
the input string is incorrect. Then, if i try with a comma instead of
a dot, it works fine.

double MyDouble = double.Parse("2 0,50"); // Works fine

Isn't it supposed to be a dot that works? I think it could be related
to "Regional and Language Options" in WinXP. I'm using french canadian
regional options if it can gives you a hint. And if it is really
related to regional and language options, what should i change
exactly?

If anyone has an idea how to make it works with a dot that would be
great. I want understand why it doesn't works. Thanks!
Nov 15 '05 #1
4 17791
I'm sure it is your regional settings.

You will notice that in the Regional Options Tab (in the Regional and
Language Options) the samples will show you how the number is to be
formatted. For French Canadian, a number is this:

"123 456 789,00"

which would explain your error. Change the format to English and you won't
have the problem.

If you must have the french Canadian, then you have to use that number
format, where a comma is the decimal separator. You could also customize
and change the decimal to a period.

Hope this helps.
"Matt" <me***@rocks.co m> wrote in message
news:ki******** *************** *********@4ax.c om...
Hi there,

I'm having a weird situation when converting strings to double.
Normally, the following code would work right?

double MyDouble = double.Parse("2 0.50"); // Error at runtime

Well, it gives me an error at run time, telling me that the format of
the input string is incorrect. Then, if i try with a comma instead of
a dot, it works fine.

double MyDouble = double.Parse("2 0,50"); // Works fine

Isn't it supposed to be a dot that works? I think it could be related
to "Regional and Language Options" in WinXP. I'm using french canadian
regional options if it can gives you a hint. And if it is really
related to regional and language options, what should i change
exactly?

If anyone has an idea how to make it works with a dot that would be
great. I want understand why it doesn't works. Thanks!

Nov 15 '05 #2
"Matt" <me***@rocks.co m> wrote in message
news:ki******** *************** *********@4ax.c om...
double MyDouble = double.Parse("2 0.50"); // Error at runtime

Well, it gives me an error at run time, telling me that the format of
the input string is incorrect. Then, if i try with a comma instead of
a dot, it works fine.

double MyDouble = double.Parse("2 0,50"); // Works fine

Isn't it supposed to be a dot that works? I think it could be related
to "Regional and Language Options" in WinXP. I'm using french canadian
regional options if it can gives you a hint. And if it is really
related to regional and language options, what should i change
exactly?

If anyone has an idea how to make it works with a dot that would be
great. I want understand why it doesn't works. Thanks!


Try:
double.Parse("2 0.50", new System.Globaliz ation.CultureIn fo("en-US"));

And yes, it's about regional options... :)
Nov 15 '05 #3
Well it was the regional settings. I just set it to Canadian English
and it works fine for both.

However it means that this section of code will depend of the user's
regional settings. Fortunately for me it's an asp.net project that
will run on a specific server. But if it was a c# program made for
deployment on different computers, that would be problematic.
Nov 15 '05 #4
Matt,

Everyone has this number from string parse problem. As an American
living in Europe, with a french computer programing for the US, I got
to it quicker. If you need to reliably convert a number to and from a
string, there is nothing better than "forcing" the culture to
CultureInfo.Inv ariantCulture. You will find it (if not exactly) very
similar to en-US. so parsing would go like:
double dbl = double.Parse("1 234.56",
System.Globaliz ation.CultureIn fo.InvariantCul ture);

And when you need to get your string from the double, you can do the
same thing in "reverse":
string s =
dbl.ToString(Sy stem.Globalizat ion.CultureInfo .InvariantCultu re);

Scott

"Matt" <me***@rocks.co m> wrote in message
news:s9******** *************** *********@4ax.c om...
Well it was the regional settings. I just set it to Canadian English
and it works fine for both.

However it means that this section of code will depend of the user's
regional settings. Fortunately for me it's an asp.net project that
will run on a specific server. But if it was a c# program made for
deployment on different computers, that would be problematic.

Nov 15 '05 #5

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

Similar topics

11
2529
by: Faheem Mitha | last post by:
Hi, I'm not sure what would be more appropriate, so I'm ccing it to both alt.comp.lang.learn.c-c++ and comp.lang.python, with followup to alt.comp.lang.learn.c-c++. While working with a random number generator in the context of a mixed Python/C++ programming problem. I encountered a vexing type conversion problem.
5
1858
by: ann | last post by:
Does somebody know why I get a blank string in strA? Last time post the wrong code. " Option Strict On Option Explicit On Public Class Cast Private Sub FuncA()
3
6075
by: Ice Man | last post by:
Hi I want to send e-mails using an asp page first I create the mail Object: Set objMail = Server.CreateObject("CDONTS.NewMail") After I fill a variable with the html code that will be the mail txtMailBody = "<html>" txtMailBody = txtMailBody & "<center>Hi <BR> This is a test"
2
2333
by: Darryl A. J. Staflund | last post by:
Hi there, Can anyone tell me why invoking a single SQL insert statement (well, rather, a method that performs a SQL insert) using an asynchronous delegate should result in twice the number of records being inserted? Am I just making a mistake somewhere? (though I don't get double the records if I call the method synchronously.) Thanks, Darryl
1
2641
by: Michael Tissington | last post by:
I'm trying to convert a project from VS2003 to VS2005 After conversion all of my TagPrefix are not recognized in the body. <%@ Register TagPrefix="Oaklodge" TagName="Curve" Src="ctrls/Curve.ascx" %> This does not report any errors, but when I try to use it like <Oaklodge:Curve runat="server" /> I get the following error
0
1117
by: egbert.beuker | last post by:
Hi, I encountered a conversion problem in my .net web app (c#), and I hope someone can help me: I'm working on a generic way to store data in a database with a few generated classes. I want to loop through posted values, store them in properties in a class, and then save the data with the class function "Update", which by the way works fine.
0
2400
by: ipoxygen | last post by:
Hi, I do have 6 identical tables on six different databases (same server). I would like to merge them into one single table for reporting purposes. For the majority of the table it does work without a problem with following procedure: /* 100: NL 200: BE 300: UK 400: FR 600: SP
15
4954
by: ABC | last post by:
Hi, I have a problem with Double submission in html forms. I am using PHP as the server side scripting language, i have found a means to capture the second form submission while the first form submission is still in-progress. Basically, i can use sessions to check if the first submission is active and reject subsequent submits. ***I do not want to try any client side solution(such as disabling submit button) as hitting F5 on the...
0
1587
by: santhescript01 | last post by:
Unicode to non unicode conversion problem -------------------------------------------------------------------------------- Hi All, I am using C dll in macro which converts Unicode data to 8 bit encoding data ' Prototype of C function. ' extern "C" int _stdcall Uni2Eni(wchar_t * uni, unsigned char * eni, int size)
0
8706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8633
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8947
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8902
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7787
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6552
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5891
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.