Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 c# 对这样的值进行四舍五入:
1.1 => 1.5 2.0 => 2.0 2.1 => 2.5 1.9 => 1.5 7.7 => 7.5
我总是希望价值在0.5或0.0
0.5
0.0
if(no-(int)no!=0.0) no=(int)no+0.5
double d = 1.1; if (d != Math.Floor(d)) d = Math.Floor(d) + 0.5;
请尝试此操作并检查所有值。
希望它有效!