Tuesday, March 20, 2012

problem with float data type

Hi all,
I have declared a field with datatype as float.
When I enter value with two precision it chooses to round off to lower value and insert into the database.

I am losing precision in this case.

I want to insert 4.56. It inserts the way shown and hence all my further calculations go haywire.

Is SQL server designed to store float like this or Am I doing soemting wrong ?

Please advise...

4.56 (Inserted)

4.5599999999999996 (Stored)Generally you have to convert the value that is being inserted into the database, or you can convert it when it is pulled from the DB. I prefer to do it beforehand.

If you do something like this it should work:

Dim Val1 as Int16

Val1 = Convert.ToInt16(TextBox1.text)

No comments:

Post a Comment