开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜