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

double string convert

When i try it like you say, he ignores the dot.

For example

s = "12.45";
d = double.Parse(s);

d will be 1245.0 :(

pls help

Jul 6 '07 #1
2 2094
On Fri, 06 Jul 2007 01:48:13 -0700, <Ni****************@googlemail.com
wrote:
When i try it like you say, he ignores the dot.

For example

s = "12.45";
d = double.Parse(s);

d will be 1245.0 :(
What are your culture settings? Clearly, parsing "12.45" as a double
would normally work in the context of a US-configured computer. I will
hazard a guess that you're using the comma for the decimal separator, and
the period for the thousands separator. If that's the case, then you need
to parse "12,45" if you expect to have a value returned that is twelve and
forty-five hundredths.

There are overloads for the Parse() method that take culture-specific
format providers, so if you know the string is from a specific culture
that may be different from what the user has configured, you can use those
to ensure correct conversion.

Pete
Jul 6 '07 #2
<Ni****************@googlemail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
When i try it like you say, he ignores the dot.

For example

s = "12.45";
d = double.Parse(s);

d will be 1245.0 :(
This is because the default Culture that you are using defines de dot as
a thousands separator instead of a decimal point. You can either write your
string with a comma for the decimal point ("12,45"), or change the
CurrentCulture, or change the FormatProvider of the Parse method:

using System.Globalization;
....
CultureInfo ci = new CultureInfo("en-US");
....
s = "12.45";
d = double.Parse(s, ci);

Jul 6 '07 #3

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
14
by: Lyle Fairfield | last post by:
d1 and d2 are numbers we can store as doubles (8 bytes). d1 > 0 d2 > 0 d1 < d2 Now s1 and s2 are strings of length 8 bytes. (We can ignore unicode here). Into s1 and s2 we copy the 8 bytes...
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...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
11
by: Ole Nielsby | last post by:
First, sorry if this is off-topic, not strictly being a C++ issue. I could not find a ng on numerics or serialization and I figure this ng is the closest I can get. Now the question: I want...
14
by: kanepart2 | last post by:
Hi guys, I am having a problem with the following code snippet:- double x = (myReader); double y = (myReader); Resulting in the follwing compilation error: Cannot implicitly convert type...
5
by: Evyn | last post by:
Hi all, I have recently asked for advice: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/1b42e6855a2c571b/e63d8f10b51f015c?lnk=raot#e63d8f10b51f015c My task is to convert a...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.