472,805 Members | 817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 4435
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.