-4.6 returns as -4.6000000000000005

-4.6 returns as -4.6000000000000005

Postby 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
zsessary
 
Posts: 10
Joined: Thu 25 Mar 2010 20:05

Postby 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

Postby 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
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

I am having the same problem

Postby 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.
degas
 
Posts: 77
Joined: Mon 16 Feb 2009 18:36
Location: Argentina

Postby 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.
Pinturiccio
Devart Team
 
Posts: 2024
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for Oracle