double/float insert into mssql

  • Thread starter Thread starter Jan Agermose
  • Start date Start date
J

Jan Agermose

Im writing a small test app that reads stringvalues, parses them to
doubles and inserts the doubles into a mssql database. But the values
inserted are not the same as the original string values?

I tried paring the values using one of the two linies:

double vekselkurs =
double.Parse(node.Attributes["rate"].Value.Replace(".", ","));

//double vekselkurs = double.Parse(node.Attributes["rate"].Value, new
System.Globalization.CultureInfo("en-US"));

And adding the value as an argument to my SP using

paramater = new SqlParameter("@vekselkurs", SqlDbType.Float);
paramater.Value = vekselkurs;
command.Parameters.Add(paramater);

The values I read are:

743.27
617.23
1133.12
81.25
88.69
8.52
492.10
....

The values as seen from the database querytool:

743.26999999999998
617.23000000000002
1133.1199999999999
81.25
88.689999999999998
8.5199999999999996
492.10000000000002
....

Why is that? I tryed using float in my c# code but that makes matters worse.



Regards
Jan
 

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

Back
Top