Single to Float conversion

  • Thread starter Thread starter Christopher DuBuc
  • Start date Start date
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
 
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
 
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
 
Back
Top