Convert to double is country depending.

E

Edwin Knoppert

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?
 
N

neilmcguigan

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.CurrentCulture = 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.CurrentCulture = new
System.Globalization.CultureInfo("en-ca");

1,1 will be converted to 11
 
E

Edwin Knoppert

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.
 
G

Giraffe

* Edwin Knoppert said:
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
 
E

Edwin Knoppert

ha!
Will try that :)


Giraffe said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top