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

read sql server's decimal value to asp.net double? How?

P: n/a
Hi everyone!

I'm using greece - greek in my control panel's regional options,
and so, my decimal point is the comma (,),
while it is the dot (.) for the sql server db,

however, I'm facing trouble when I need to parse the sql server decimal as
an asp.net double!

For example:
Expand|Select|Wrap|Line Numbers
  1. ?Double.Parse("0.03", New System.Globalization.CultureInfo("el-gr"))
  2. 3.0
  3. ?Double.Parse("0.03", New System.Globalization.CultureInfo("en-US"))
  4. 0.03
  5.  
  6. ?Double.Parse("1,0", New System.Globalization.CultureInfo("el-gr"))
  7. 1.0
  8. ?Double.Parse("1,0", New System.Globalization.CultureInfo("en-US"))
  9. 10.0
  10.  
The first culture has problems with the dot (.),
while the second has problems with the comma (,)!

How on earth am I supposed to do this thing?

Thanks in advance!
Feb 1 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi everyone!
>
I'm using greece - greek in my control panel's regional options,
and so, my decimal point is the comma (,),
while it is the dot (.) for the sql server db,

however, I'm facing trouble when I need to parse the sql server decimal as
an asp.net double!

For example:
Expand|Select|Wrap|Line Numbers
  1. ?Double.Parse("0.03", New System.Globalization.CultureInfo("el-gr"))
  2. 3.0
  3. ?Double.Parse("0.03", New System.Globalization.CultureInfo("en-US"))
  4. 0.03
  5. ?Double.Parse("1,0", New System.Globalization.CultureInfo("el-gr"))
  6. 1.0
  7. ?Double.Parse("1,0", New System.Globalization.CultureInfo("en-US"))
  8. 10.0
  9.  

The first culture has problems with the dot (.),
while the second has problems with the comma (,)!

How on earth am I supposed to do this thing?

Thanks in advance!
If the value in SqlServer really is a decimal, I think it is better to
stick to numbers and not mess with strings inbetween.

So: the "object" value that is returned in the dataset needs to be cast
to a decimal, which can then be cast to a double. So something like:

double mydouble =
(double)(decimal)MyDataTable.Rows[0]["mydecimalcolumn"];

Hans Kesting
Feb 1 '07 #2

P: n/a
same thing with your suggestion,
works with "1,0" but doesn't work with "0.03" (the last is converted to 3.0)!

Any other suggestions?

"Hans Kesting" wrote:
Hi everyone!

I'm using greece - greek in my control panel's regional options,
and so, my decimal point is the comma (,),
while it is the dot (.) for the sql server db,

however, I'm facing trouble when I need to parse the sql server decimal as
an asp.net double!

For example:
Expand|Select|Wrap|Line Numbers
  1.  ?Double.Parse("0.03", New System.Globalization.CultureInfo("el-gr"))
  2.  3.0
  3.  ?Double.Parse("0.03", New System.Globalization.CultureInfo("en-US"))
  4.  0.03
  5.  
  6.  ?Double.Parse("1,0", New System.Globalization.CultureInfo("el-gr"))
  7.  1.0
  8.  ?Double.Parse("1,0", New System.Globalization.CultureInfo("en-US"))
  9.  10.0
  10.  
The first culture has problems with the dot (.),
while the second has problems with the comma (,)!

How on earth am I supposed to do this thing?

Thanks in advance!

If the value in SqlServer really is a decimal, I think it is better to
stick to numbers and not mess with strings inbetween.

So: the "object" value that is returned in the dataset needs to be cast
to a decimal, which can then be cast to a double. So something like:

double mydouble =
(double)(decimal)MyDataTable.Rows[0]["mydecimalcolumn"];

Hans Kesting
Feb 1 '07 #3

P: n/a
same thing with your suggestion,
works with "1,0" but doesn't work with "0.03" (the last is converted to 3.0)!

Any other suggestions?
Some questions:
- what is the columntype in sqlserver? ((n)varchar or decimal?)
- how are you retrieving the value from the table into your C# code?
(just a straight 'select <columnname>' from the table, or maybe a
'convert(varchar, <column>)' somewhere?)
- does anything happen with that value between retrieving and
converting? (a "ToString()" somewhere?)
- how are you trying to convert it to that final double?

*if* the value is really stored as decimal inside sqlserver, then it's
not stored as "0.03" (that is, with a "decimal dot" as opposed to a
"decimal comma"). It is stored as some binary code. Only when you
*display* the value, the software converting the binary value to a
string will decide between comma and dot.
So if you are not converting it to a string somewhere inbetween, you
should have no problems with culture specific decimal markers.

Hans Kesting

"Hans Kesting" wrote:
>>Hi everyone!

I'm using greece - greek in my control panel's regional options,
and so, my decimal point is the comma (,),
while it is the dot (.) for the sql server db,

however, I'm facing trouble when I need to parse the sql server decimal as
an asp.net double!

For example:
Expand|Select|Wrap|Line Numbers
  1. ?Double.Parse("0.03", New System.Globalization.CultureInfo("el-gr"))
  2. 3.0
  3. ?Double.Parse("0.03", New System.Globalization.CultureInfo("en-US"))
  4. 0.03
  5. ?Double.Parse("1,0", New System.Globalization.CultureInfo("el-gr"))
  6. 1.0
  7. ?Double.Parse("1,0", New System.Globalization.CultureInfo("en-US"))
  8. 10.0

The first culture has problems with the dot (.),
while the second has problems with the comma (,)!

How on earth am I supposed to do this thing?

Thanks in advance!

If the value in SqlServer really is a decimal, I think it is better to
stick to numbers and not mess with strings inbetween.

So: the "object" value that is returned in the dataset needs to be cast
to a decimal, which can then be cast to a double. So something like:

double mydouble =
(double)(decimal)MyDataTable.Rows[0]["mydecimalcolumn"];

Hans Kesting

Feb 2 '07 #4

P: n/a
yes you are right!

that was it, I found it yesterday,
my pc has "," as decimal point,
while I stored the other value in the db (as varchar) using "." as decimal,
confused with how sql server stores decimals!

Anyway, thanks all for your answers guys!

"Hans Kesting" wrote:
same thing with your suggestion,
works with "1,0" but doesn't work with "0.03" (the last is converted to 3.0)!

Any other suggestions?

Some questions:
- what is the columntype in sqlserver? ((n)varchar or decimal?)
- how are you retrieving the value from the table into your C# code?
(just a straight 'select <columnname>' from the table, or maybe a
'convert(varchar, <column>)' somewhere?)
- does anything happen with that value between retrieving and
converting? (a "ToString()" somewhere?)
- how are you trying to convert it to that final double?

*if* the value is really stored as decimal inside sqlserver, then it's
not stored as "0.03" (that is, with a "decimal dot" as opposed to a
"decimal comma"). It is stored as some binary code. Only when you
*display* the value, the software converting the binary value to a
string will decide between comma and dot.
So if you are not converting it to a string somewhere inbetween, you
should have no problems with culture specific decimal markers.

Hans Kesting

"Hans Kesting" wrote:
>Hi everyone!

I'm using greece - greek in my control panel's regional options,
and so, my decimal point is the comma (,),
while it is the dot (.) for the sql server db,

however, I'm facing trouble when I need to parse the sql server decimal as
an asp.net double!

For example:
Expand|Select|Wrap|Line Numbers
  1. ?Double.Parse("0.03", New System.Globalization.CultureInfo("el-gr"))
  2. 3.0
  3. ?Double.Parse("0.03", New System.Globalization.CultureInfo("en-US"))
  4. 0.03
  5. ?Double.Parse("1,0", New System.Globalization.CultureInfo("el-gr"))
  6. 1.0
  7. ?Double.Parse("1,0", New System.Globalization.CultureInfo("en-US"))
  8. 10.0

The first culture has problems with the dot (.),
while the second has problems with the comma (,)!

How on earth am I supposed to do this thing?

Thanks in advance!

If the value in SqlServer really is a decimal, I think it is better to
stick to numbers and not mess with strings inbetween.

So: the "object" value that is returned in the dataset needs to be cast
to a decimal, which can then be cast to a double. So something like:

double mydouble =
(double)(decimal)MyDataTable.Rows[0]["mydecimalcolumn"];

Hans Kesting


Feb 2 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.