Single to Float conversion

C

Christopher DuBuc

Hello,

I am using VB.NET & SQL Server CE and I am trying to add
data to a FLOAT column using a variable of type SINGLE.
The problem I am having is that when I enter in a value
of say 2.9 in via a control (textbox) it ends up in the
database stored as 2.9000000000095367...etc.

More specifically: I extract a DataTable from the SQLCE
table with a DataAdapter, add a new row, update the new
row/column with the a SINGLE variable, and then save the
back to the database with a SQLCECommandBuilder table
update.

Is there a special conversion function I need to go from
SINGLE datatype to a FLOAT data column? Or do I have to
change everything to decimal datatype/ numeric data
column? I know that if I do a manual insert of 2.9 into a
FLOAT column via a SQL statement, then the exact value of
2.9 gets inserted...so why doesn't that work via a data
adapter?

Thanks in Advance,

Chris
 
C

Chris Tacke, eMVP

That's how floats work, you entered 2.9, but it's not exactly 2.9 in float
terms, never will be. This is why you should use decimals unless you
specifically need floats (you could also round ther results when you get
data out of it).

-Chris
 
C

Christopher DuBuc

Fair enough...thanks Chris.

I'm still confused about why if I enter the value 2.9
through a manual INSERT statement (via SQLCE Query
Analyzer), then the database stores the number exactly...I
guess I'll try to do some research on that one.

Cheers,

Chris
 

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