-4.6 returns as -4.6000000000000005

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
zsessary
Posts: 10
Joined: Thu 25 Mar 2010 20:05

-4.6 returns as -4.6000000000000005

Post by zsessary » Thu 25 Mar 2010 20:29

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 26 Mar 2010 15:42

Thnak you for the report, we have reproduced the situation.
I will let you know about the results of our investigation.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 16 Apr 2010 11:15

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

degas
Posts: 77
Joined: Mon 16 Feb 2009 18:36
Location: Argentina

I am having the same problem

Post by degas » Mon 02 Jan 2012 20:02

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.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Tue 03 Jan 2012 14:04

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.

Post Reply