473,804 Members | 3,030 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 17796
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
2540
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
1864
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
6081
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
2336
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
2649
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
1123
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
2403
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
4964
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
1608
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
9706
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
9579
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
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
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
10075
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
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.