Compare double till precision 2
I want to compare two double values till the second digit from decimal point. I am using following statement but I think it is not working properly.
dbl1.ToString("g2", CultureInfo.InvariantCulture).Equals( dbl2.ToString("g2", CultureInfo.InvariantCulture))
Am I missing anything 开发者_JS百科here?
You could use Math.Abs(dbl1 - dbl2) < 0.01
. This will only consider the first two digits after the decimal point.
dbl1.ToString("g2", CultureInfo.InvariantCulture).Equals( dbl2.ToString("g2", CultureInfo.InvariantCulture))
is working for me. I was just looking for any other alternative.
精彩评论