By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

double/float insert into mssql

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jan Agermose <ja@conviator.com> wrote:
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?


See http://www.pobox.com/~skeet/csharp/floatingpoint.html

You might want to consider using decimal instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.