EylonM
asked on
Inserting into Float field in sql table
hi! i am reading a line from a csv file, splitting the line using the split method, and parsing the array, inserting the values into an sql table. one of my fields is defined as type float. i using the following code to convert the string to a float and insert into my field. the float inserted is correct except that it has a lot of garbage added to it. does anyone know why this happens?
here is the code:
value = splitLine[lineIndex];
insertSql.AddFieldValuePai r("VIN", "@VINParam");
Single f = Convert.ToSingle(value);
if (myCommand.Parameters.Inde xOf("@VINP aram") < 0)
myCommand.Parameters.Add(" @VINParam" , System.Data.SqlDbType.Floa t).Value = f;
else
myCommand.Parameters["@VIN Param"].Va lue = value;
lineIndex += 1;
for example, when the float value is: 16.43437
i get:16.434370040893555
here is the code:
value = splitLine[lineIndex];
insertSql.AddFieldValuePai
Single f = Convert.ToSingle(value);
if (myCommand.Parameters.Inde
myCommand.Parameters.Add("
else
myCommand.Parameters["@VIN
lineIndex += 1;
for example, when the float value is: 16.43437
i get:16.434370040893555
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That isn't garbage, that is how the computer has that number stored in memory. Non integral values are just an 'approximate' value
If you really want the details then look here for more info.
http://en.wikipedia.org/wiki/Floating_point
http://en.wikipedia.org/wiki/Floating_point