Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have two 2-D double arrays.I need to compare each value from these two arrays after rounding to 4 decimal places.(both are having same rows and columns).I have the code
C#
var equal = data1.Rank == data2.Rank &&
Enumerable.Range(0, data1.Rank).All(dimension => data1.GetLength(dimension) == ¬
data2.GetLength(dimension)) &&
data1.Cast<double>().SequenceEqual(data2.Cast<double>());



This shows wrong result..because it is not rounding the values.
I need to compare values after rounding to 4 decimals.Pls help
Posted
Updated 18-Feb-15 1:21am
v3
Comments
John C Rayan 18-Feb-15 8:53am    
I have tested the solution and it works fine.

1 solution

XML
var equal = data1.Rank == data2.Rank &&
            Enumerable.Range(0, data1.Rank).All(dimension => data1.GetLength(dimension) == data2.GetLength(dimension)) && data1.Cast<double>().Select(v => Math.Round(v, 4)).SequenceEqual(data2.Cast<double>().Select(v => Math.Round(v, 4)));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900