472,778 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,778 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 2065
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.