473,395 Members | 1,680 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.

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

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

Similar topics

2
by: John Bowling | last post by:
I'm trying to read a file that contains text for a decimal count, convert it to binary, increment and write it back out. I'm using Java 2 in SuSE 8.2, installed from the SuSE CD's. When using...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
3
by: Koen | last post by:
Hi, first of all, the machine setup server 1: - UDB2 7.2.5; COUNTRY=1, location = US, IBM1250 codepage - Locale: US English; Regional Settings: English; Keyboard: Dutch; decimal separator: ....
4
by: Ron | last post by:
Greetings, int i = 1, j = 6; double k = (double)i/j; Console.WriteLine(k.ToString()); Console.WriteLine(string.Format(k.ToString(), "0.00")); both yield 0.166666666666667 how can I make...
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
5
by: Franky | last post by:
Can a Decimal variable be set to "Not a Number" I've been looking in the help and can't find any reference to that. Thanks in advance
0
by: heplesser | last post by:
Summary: Does the C++ standard require std::basic_istream<>::operator>>(double&) to leave the input stream untouched in case of a read failure? Details: I noticed an unexpected behavior of...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.