473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Convert to double is country depending.


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
4 4492
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
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
* 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: abracad | last post by:
Hi Is there any (preferably free) PHP script that will identify the country of a visitor, thus allowing one page to be delivered to those from A, B and C, and another to those from X, Y and Z? ...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: orc | last post by:
Hi there, I'm receiving a variant time parameter (double) from a dll but how do I convert it to something useful in C#? Your help is highly appreciated! Thanks, orc
10
by: zelyal | last post by:
I got : An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. at execution of simple line: double...
0
by: MarcoDieleman | last post by:
Hello you all, I have this code that is written in MS Transact-SQL and I need to convert it to work with Oracle. Can anyone please help??? I need the code for a VBscript project. Thanks! ...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
2
by: yogi_bear_79 | last post by:
I have a double of unknown length that I need to split at the decimal. I thought I would convert it either to a string or a char. char seems to be the best since it easily lends itself to...
1
by: adamjblakey | last post by:
Hi, At the moment i have a country and region ajax list so depending on which country you select the region field will auto fill. Now this is the code that makes this work: JS var...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.