By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,671 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,671 IT Pros & Developers. It's quick & easy.

double string convert

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
<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.