467,872 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,872 developers. It's quick & easy.

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
  • viewed: 1897
Share:
2 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by cindy liu | last post: by
14 posts views Thread by Lyle Fairfield | last post: by
17 posts views Thread by David Scemama | last post: by
4 posts views Thread by Edwin Knoppert | last post: by
11 posts views Thread by Ole Nielsby | last post: by
14 posts views Thread by kanepart2 | last post: by
5 posts views Thread by Evyn | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.