我有此代码:
var t = (timer2Seconds / 10).ToString()
When timer2Seconds is 100 then t is 100
When timer2Seconds is 99 then t is 9
有一种方法可以使它四舍五入,以便:
When timer2Seconds is 99 then t is 10
When timer2Seconds is 91 then t is 10
When timer2Seconds is 90 then t is 9
答案 0 :(得分:1)
使用公式:
var d = 10;
var t = (timer2Seconds + d - 1) / d;
它适用于整数并四舍五入。