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

G

Guest

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!
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

Mike9900 said:
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!
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Mike9900 said:
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

Mike9900 said:
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!
 
G

Guest

Yes thanks!

But what is the solution?
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

Mike9900 said:
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

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!
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Mike9900 said:
Yes thanks!

But what is the solution?
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

Mike9900 said:
That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike


:

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]
- (e-mail address removed)

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!
 
G

Guest

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 said:
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]
- (e-mail address removed)

Mike9900 said:
Yes thanks!

But what is the solution?
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

That's true, but storing that in ADO.NET table which has Decimal column
create a problem.
--
Mike


:

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]
- (e-mail address removed)

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!
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)

Mike9900 said:
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 said:
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]
- (e-mail address removed)

Mike9900 said:
Yes thanks!

But what is the solution?
--
Mike


:

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]
- (e-mail address removed)

That's true, but storing that in ADO.NET table which has Decimal
column
create a problem.
--
Mike


:

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]
- (e-mail address removed)

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!
 
G

Guest

thanks
--
Mike


Nicholas Paldino said:
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]
- (e-mail address removed)

Mike9900 said:
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 said:
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]
- (e-mail address removed)

Yes thanks!

But what is the solution?
--
Mike


:

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]
- (e-mail address removed)

That's true, but storing that in ADO.NET table which has Decimal
column
create a problem.
--
Mike


:

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]
- (e-mail address removed)

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top