本文介绍了如何通过除以小数来获得准确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码
I have this code
decimal total = 2m;
decimal discount = 0.2m;
decimal disPercent = discount / total;
disPercent值应为0.0909090909090909
但我得到0.1
我该怎么办才能得到0.0909090909090909?
请注意值是例如,我总是从数据库中得到它们作为十进制价值
我的尝试:
disPercent value should be 0.0909090909090909
but I get 0.1
what should I do to get 0.0909090909090909?
note that the values are for example, I always get them from database as decimal values
What I have tried:
decimal total = 2m;
decimal discount = 0.2m;
decimal disPercent = decimal.Divide(discount, total);
无法正常工作
not working
推荐答案
0.2 / 2.0 == 2.0 / 20.0 == 1.0 / 10.0 == 0.1
这篇关于如何通过除以小数来获得准确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!