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

Convert to double is country depending.

P: n/a

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 it seems this convert is determined by the local settings and comma
is indeed used as decimal separator.

Is there another way to convert a dotted value to a double variable?

Like 1234.5 and not 1234,5

Also, how to determine (and not knowing it) the decimals seperator?
convert to string?
Jul 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
is this 1.1 or 2.0?

what language is your browser set to?

Firefox: Menu bar - tools - options - advanced tab - languages - edit
languages - what is the top value in the list?

IE: menu bar - tools - internet options - languages - what is the top
value in the list?

asp.net 2.0 has auto globablization so it will set the culture of the
current thread to whatever your browser's first choice is. 1.1 you have
to do this manually

if you set the current thread culture to Canadian French (where comma
is the placeholder)

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("fr-ca");

1,1 will be converted to 1,1

if you set the current thread's culture to Canadian English (where dot
is the placeholder)

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("en-ca");

1,1 will be converted to 11

Edwin Knoppert wrote:
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 it seems this convert is determined by the local settings and comma
is indeed used as decimal separator.

Is there another way to convert a dotted value to a double variable?

Like 1234.5 and not 1234,5

Also, how to determine (and not knowing it) the decimals seperator?
convert to string?
Jul 20 '06 #2

P: n/a
I don't think the browser is the issue since my gridview put;s the variable
as text in a textbox (doublefield)
I'm using dutch where , (comma) is normal while as programmer i think it's
not.
Even the numpad does not have a comma so it's a useless notation imo.

But since i'm only looking for a decimal seperator and not a thousand sep.
(not used/shown) i simply need to fetch the textbox text and convert it to a
double.
I just wrote a dumb function which inspects what the resuilt is of double to
string, comma or dot and use that to replace it in the value text.
Then i convert it.
This is the next culture specific **** functionality MS invents, we have
messed for years in VB with dates right?
At least a date conversion from and to a double exists so it's
interchangable.
So far i have not found a reliable native function to convert a value text
to double.
In ordinary programming languages it was sufficient to convert a comma to
dot and use VAL(). (always good)
I'm using c# where val() is not around, the math object shows no similar
function.


<ne**********@gmail.comschreef in bericht
news:11**********************@m79g2000cwm.googlegr oups.com...
is this 1.1 or 2.0?

what language is your browser set to?

Firefox: Menu bar - tools - options - advanced tab - languages - edit
languages - what is the top value in the list?

IE: menu bar - tools - internet options - languages - what is the top
value in the list?

asp.net 2.0 has auto globablization so it will set the culture of the
current thread to whatever your browser's first choice is. 1.1 you have
to do this manually

if you set the current thread culture to Canadian French (where comma
is the placeholder)

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("fr-ca");

1,1 will be converted to 1,1

if you set the current thread's culture to Canadian English (where dot
is the placeholder)

System.Threading.Thread.CurrentThread.CurrentCultu re = new
System.Globalization.CultureInfo("en-ca");

1,1 will be converted to 11

Edwin Knoppert wrote:
>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 it seems this convert is determined by the local settings and
comma
is indeed used as decimal separator.

Is there another way to convert a dotted value to a double variable?

Like 1234.5 and not 1234,5

Also, how to determine (and not knowing it) the decimals seperator?
convert to string?

Jul 20 '06 #3

P: n/a
* Edwin Knoppert wrote:
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 it seems this convert is determined by the local settings and comma
is indeed used as decimal separator.

Is there another way to convert a dotted value to a double variable?

Like 1234.5 and not 1234,5

Also, how to determine (and not knowing it) the decimals seperator?
convert to string?

set the culture info...
Thread.CurrentThread.CurrentCulture = new CultureInfo("foo-Bar", true);

where foo-Bar = en-GB or summink... or

System.Globalization.NumberFormatInfo info = new
System.Globalization.NumberFormatInfo();
info.NumberDecimalSeparator = ",";
info.NumberGroupSeparator = ".";
double d = Convert.ToDouble("1234,5", info);

will give you 1234.5 not 1234,5..... HTH

Jul 20 '06 #4

P: n/a
ha!
Will try that :)
"Giraffe" <mr********@mr.giraffe.zo.o.comschreef in bericht
news:e9**********@custnews.inweb.co.uk...
>* Edwin Knoppert wrote:
>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 it seems this convert is determined by the local settings and
comma
is indeed used as decimal separator.

Is there another way to convert a dotted value to a double variable?

Like 1234.5 and not 1234,5

Also, how to determine (and not knowing it) the decimals seperator?
convert to string?


set the culture info...
Thread.CurrentThread.CurrentCulture = new CultureInfo("foo-Bar", true);

where foo-Bar = en-GB or summink... or

System.Globalization.NumberFormatInfo info = new
System.Globalization.NumberFormatInfo();
info.NumberDecimalSeparator = ",";
info.NumberGroupSeparator = ".";
double d = Convert.ToDouble("1234,5", info);

will give you 1234.5 not 1234,5..... HTH

Jul 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.