Microsoft KB Archive/326601

= BUG: Rounding problem when a column expression is computed =

Article ID: 326601

Article Last Modified on 3/13/2006

-

APPLIES TO


 * Microsoft ADO.NET 1.0
 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft ADO.NET 2.0

-



This article was previously published under Q326601



SYMPTOMS
When you evaluate the expression that is specified in a computed column of a DataRow, incorrect results may be returned if the expression contains integer division. The resulting expression is rounded inconsistently.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the behavior
The following code demonstrates the problem: using System; using System.Data;

class Test {   public static void Main {       try {           // Create a table with 3 columns. DataTable dt = new DataTable; dt.Columns.Add(&quot;Col1&quot;, typeof(int)); dt.Columns.Add(&quot;Col2&quot;, typeof(int)); DataColumn dc = dt.Columns.Add(&quot;Col3&quot;, typeof(int)); dc.Expression = &quot;Col1 / Col2&quot;;

// Add the first row. DataRow row = dt.NewRow; row.ItemArray = new object[] { 3, 2 }; dt.Rows.Add(row); Console.WriteLine(row[1]);

// Add the second row. row = dt.NewRow; row.ItemArray = new object[] { 5, 2 }; dt.Rows.Add(row); Console.WriteLine(row[2]); }       catch(Exception exc) {           Console.WriteLine(exc); }   } } The output appears as follows: 2 2 The data types in the computed column imply integer division. However, the expression &quot;3 / 2&quot; evaluates to &quot;2&quot; for the first row instead of &quot;1&quot;. The expression &quot;5 / 2&quot; in the second row returns the correct results.

According to the rules of integer division, you expect output to appear as follows: 1 2

Keywords: kbbug kbpending KB326601

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.