473,397 Members | 1,950 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,397 software developers and data experts.

Saving a number with high preciosion in a ADO.NET table

I save a number in the table and want to get that number again, but the
number I get has lower precision than I expect. For example, when I divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But saving
this result into a table with a column of type Double decreases the precision
to 3.333333333333333 , so when I get this number and multiply it 10 I do not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of type float
and can save a number such as 3.3333333333333335, the ADO.NET table must also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #1
9 1635
Mike,

Well, you are always going to have a problem here, in that neither of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the database
as a decimal type, which will maintain precision to the number of places
that you specify (at least in SQL server). On the .NET side, you would use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
>I save a number in the table and want to get that number again, but the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10 I do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of type
float
and can save a number such as 3.3333333333333335, the ADO.NET table must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #2
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,

Well, you are always going to have a problem here, in that neither of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the database
as a decimal type, which will maintain precision to the number of places
that you specify (at least in SQL server). On the .NET side, you would use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
I save a number in the table and want to get that number again, but the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10 I do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of type
float
and can save a number such as 3.3333333333333335, the ADO.NET table must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #3
Mike,

It creates a problem because the underlying type in Sql server is not
decimal as well. If the type in .NET and the type in Sql server are both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
>Mike,

Well, you are always going to have a problem here, in that neither of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of places
that you specify (at least in SQL server). On the .NET side, you would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microso ft.com...
>I save a number in the table and want to get that number again, but the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10 I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of type
float
and can save a number such as 3.3333333333333335, the ADO.NET table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #4
Yes thanks!

But what is the solution?
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,

It creates a problem because the underlying type in Sql server is not
decimal as well. If the type in .NET and the type in Sql server are both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,

Well, you are always going to have a problem here, in that neither of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of places
that you specify (at least in SQL server). On the .NET side, you would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
I save a number in the table and want to get that number again, but the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10 I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of type
float
and can save a number such as 3.3333333333333335, the ADO.NET table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #5
That's what I'm trying to tell you. You indicated that the type on the
Sql Server is float, not decimal. There is a separate type in sql server
called decimal that you have to use for the column, along with the decimal
type in .NET.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.com...
Yes thanks!

But what is the solution?
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
>Mike,

It creates a problem because the underlying type in Sql server is not
decimal as well. If the type in .NET and the type in Sql server are both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microso ft.com...
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

Well, you are always going to have a problem here, in that neither
of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of
places
that you specify (at least in SQL server). On the .NET side, you
would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microso ft.com...
I save a number in the table and want to get that number again, but
the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10
I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of
type
float
and can save a number such as 3.3333333333333335, the ADO.NET table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #6
if it sufficient to only specify the decimal or I must add the precision as
well, for example, decimal(18,18). Because when I did this, it complained
and did not save.
So I am wondering if make it only as decimal it will work.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
That's what I'm trying to tell you. You indicated that the type on the
Sql Server is float, not decimal. There is a separate type in sql server
called decimal that you have to use for the column, along with the decimal
type in .NET.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.com...
Yes thanks!

But what is the solution?
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
Mike,

It creates a problem because the underlying type in Sql server is not
decimal as well. If the type in .NET and the type in Sql server are both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

Well, you are always going to have a problem here, in that neither
of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of
places
that you specify (at least in SQL server). On the .NET side, you
would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
I save a number in the table and want to get that number again, but
the
number I get has lower precision than I expect. For example, when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double. But
saving
this result into a table with a column of type Double decreases the
precision
to 3.333333333333333 , so when I get this number and multiply it 10
I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of
type
float
and can save a number such as 3.3333333333333335, the ADO.NET table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike

Jun 23 '07 #7
That's a separate issue, if it didn't save, but yes, you need to create
a decimal type in the database like that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:82**********************************@microsof t.com...
if it sufficient to only specify the decimal or I must add the precision
as
well, for example, decimal(18,18). Because when I did this, it complained
and did not save.
So I am wondering if make it only as decimal it will work.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
> That's what I'm trying to tell you. You indicated that the type on
the
Sql Server is float, not decimal. There is a separate type in sql server
called decimal that you have to use for the column, along with the
decimal
type in .NET.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:9D**********************************@microso ft.com...
Yes thanks!

But what is the solution?
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

It creates a problem because the underlying type in Sql server is
not
decimal as well. If the type in .NET and the type in Sql server are
both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microso ft.com...
That's true, but storing that in ADO.NET table which has Decimal
column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

Well, you are always going to have a problem here, in that
neither
of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of
places
that you specify (at least in SQL server). On the .NET side, you
would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microso ft.com...
I save a number in the table and want to get that number again,
but
the
number I get has lower precision than I expect. For example,
when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double.
But
saving
this result into a table with a column of type Double decreases
the
precision
to 3.333333333333333 , so when I get this number and multiply it
10
I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of
type
float
and can save a number such as 3.3333333333333335, the ADO.NET
table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike

Jun 23 '07 #8
thanks
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
That's a separate issue, if it didn't save, but yes, you need to create
a decimal type in the database like that.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:82**********************************@microsof t.com...
if it sufficient to only specify the decimal or I must add the precision
as
well, for example, decimal(18,18). Because when I did this, it complained
and did not save.
So I am wondering if make it only as decimal it will work.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:
That's what I'm trying to tell you. You indicated that the type on
the
Sql Server is float, not decimal. There is a separate type in sql server
called decimal that you have to use for the column, along with the
decimal
type in .NET.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:9D**********************************@microsof t.com...
Yes thanks!

But what is the solution?
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

It creates a problem because the underlying type in Sql server is
not
decimal as well. If the type in .NET and the type in Sql server are
both
decimal, then you should get the values consistently in both.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
That's true, but storing that in ADO.NET table which has Decimal
column
create a problem.
--
Mike
"Nicholas Paldino [.NET/C# MVP]" wrote:

Mike,

Well, you are always going to have a problem here, in that
neither
of
these values will exactly equal 10/3.

For the most accuracy, you will want to store the value in the
database
as a decimal type, which will maintain precision to the number of
places
that you specify (at least in SQL server). On the .NET side, you
would
use
the Decimal type when working with these values.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
I save a number in the table and want to get that number again,
but
the
number I get has lower precision than I expect. For example,
when I
divide
10/3 I get 3.3333333333333335 if the variable is of type Double.
But
saving
this result into a table with a column of type Double decreases
the
precision
to 3.333333333333333 , so when I get this number and multiply it
10
I
do
not
get that exact number which is 10.

How can I solve this problem? so when a field in SQL Server is of
type
float
and can save a number such as 3.3333333333333335, the ADO.NET
table
must
also
save such number if it is of type Double or Decimal.

I had no choice except to use String!
--
Mike
Jun 23 '07 #9


how to store decimal or amount like 455.587 in ado.net table

*** Sent via Developersdex http://www.developersdex.com ***
Jun 25 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: maceo | last post by:
I have a script that will print out the results of a table and make a calculation of a total of one of the columns. See example: <?php /* Database connection */...
8
by: EAS | last post by:
Hey, I'm new to python (and programming in general) so I'll prolly be around here a lot... Anyways, I've found out how to make a "guess my number game" where the player guesses a number between...
13
by: Ron | last post by:
Hi all I'm deciding whether to use the PK also as an account number, invoice number, transaction number, etc that the user will see for the respective files. I understand that sometimes a...
18
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having...
1
by: Magnus | last post by:
I'm testing walkthrough saving data to a Database (Multiple Tables). http://msdn2.microsoft.com/en-us/library/4esb49b4(VS.80).aspx In the famous Customer/Order example, I'm getting referential...
7
by: Dick Moores | last post by:
I accidentally stumbled across the Turtle Graphics module (turtle.py) the other day and have been having some fun with it. Now I'm wondering if there is a way to build into a script the saving...
8
by: Elfae | last post by:
I have searched high and low for a sample for this, and I just can't find any. Sorry for the length! Background Information The issue revolves around setting up a system-generated increase in...
3
by: hello2008 | last post by:
Hi, I donot have much knowledge of R.Exp. In my web page I am required to validate numeric textboxes allowing signed/unsigned integer/float numbers and then compare between them. I need the...
1
by: AlisonD | last post by:
have a database that I am using a look up table. On the form the whole table appears. I have name,telephone number,fax number,address, licencesdate. I want to be able to choose the correct name for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.