I'm using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal.
0.1123456789
0.11234567891
0.11234567899
The 10 decimal limit is coming from my database, so I have to assume that the first number was already rounded, and therefore I can't simply round the others because the last one will round up.
I really just want to truncate the to 10 decimal places, but can't see how to do this either.
The same way you'd compare floating point numbers. Here's some pseudocode, because I don't know the .NET call for absolute value, but it will essentially look like this (modify the constant for the precision needed):
if( Math.Abs( value1 - value2 ) < 0.0000000001 )
{
// blah blah
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With