Page 1 of 1

-4.6 returns as -4.6000000000000005

Posted: Thu 25 Mar 2010 20:29
by zsessary
We have encountered a very strange error with dotconnect. When retrieving -4.6 from the database it actually returns -4.6000000000000005 of type Double. Obviously there's some miscalculation taking place.

So far -4.6 is the magic number; no others found. This happens when using a dataContext/LINQ to Oracle and when just using a devart.data.oracle.oracleCommand object. The DataContext designer defaulted our field to type Double? instead of type Decimal, so we just left it that way.

dotConnect version: 5.35.79pro
oracle version: 10g
database field type: NUMBER, length 11, scale 2, nullable

Thanks,
Zach

Posted: Fri 26 Mar 2010 15:42
by AndreyR
Thnak you for the report, we have reproduced the situation.
I will let you know about the results of our investigation.

Posted: Fri 16 Apr 2010 11:15
by AndreyR
Oracle performed these calculations. One can't expect the precise value when using Double, see the documentaton:
http://msdn.microsoft.com/en-us/library ... ouble.aspx

I am having the same problem

Posted: Mon 02 Jan 2012 20:02
by degas
Hi, i am having the same problem (same DevArt version) but not with LINQ, but with TypedDataSet. The problem is that the dataset update command does not work, because when it compares original values in the where clause, the values don't match so the update returns 0 rows updated. This ends up in an error being thrown.

I am using the DbMonitor and everything looks fine but when i debug it, i see the real values and they look like this:

1.021 ---> 1.0210000000000001


Is there a way to solve this.

Posted: Tue 03 Jan 2012 14:04
by Pinturiccio
You can use the NumberMappings property of OracleConnection.

Code: Select all

            OracleConnection conn = new OracleConnection("Your ConnectionString");
            conn.NumberMappings = new NumberMappingCollection();
            NumberMapping nm = new NumberMapping(OracleNumberType.Number, 1, 20, typeof(Decimal));
            conn.NumberMappings.Add(nm);
Where 1 and 20 are the lower and upper bounds of the Number precision used for this mapping rule.
If it is necessary, you can change the bounds of mapping to Decimal.
Please tell us if this helps.