3 回答

TA貢獻1898條經驗 獲得超8個贊
round()函數是4舍6入,5看奇偶。
比如 round(1.5,0)=2,round(2.5,0)=2,round(2.5001,0)=3,
這樣就是你的要求了
Int(2.5 + 0.5)=3
Int(2.499 + 0.5)=2

TA貢獻1848條經驗 獲得超2個贊
在 Option Strict Off 的情況下,可以使用 CInt 函數將其他數據類型顯式轉換為 Integer 類型。但是,Cint 并非截去數字的小數部分,而是舍入為最接近的整數。例如:
MyNumber = CInt(99.8) ' Returns 100.
MyNumber = CInt(-99.8) ' Returns -100.
MyNumber = CInt(-99.2) ' Returns -99.
自己模擬常見的四舍五入,需要 import system.math
function sishewuru(byval dblX as double) as integer
if dblx >= truncate(dblX) +0.5 then
return truncate(dblX) + 1
else
return truncate(dblX)
end if
end Function
隨便瞎寫的,你可能需要修改吧

TA貢獻1777條經驗 獲得超3個贊
在精度允許范圍內加上一點點,比如round(2.5+0.00001),結果就是3啦
private function RoundEx(byval dVal as Variant,optional byval lLen as long=0) as double
if isnumeric(dVal) then
if val(dVal)<0 then
RoundEx=round(val(dVal)-0.00000000000001,lLen)
elseif val(dVal)>0 then
RoundEx=round(val(dVal)+0.00000000000001,lLen)
else
RoundEx=0
end if
end if
end function
- 3 回答
- 0 關注
- 216 瀏覽
添加回答
舉報