C 語言中實現四捨五入: (int)(a+0.5)即可。 很巧妙的用了取整規則。 也不用匯入math.h 同樣注意負數的情況。 把+ 換成– 即可。 float f = ..; int i = (int)(f + 0.5); ...
確定! 回上一頁