将float转换为整数时舍入 [英] Rounding when converting float to integer
问题描述
Cint(3/2)= 2(四舍五入,我原以为答案是1)
Cint(5/2)= 2(向下舍入)
Access帮助说Cint()向最接近的偶数舍入,但为什么?
我是否需要滚动自己的 ;整数转换让它总是四舍五入
或者下来?
我看了Cint(3 \2)和Cint(5 \2)这似乎一直在下来......这可能会下降......
-
问候,
Br @ dley
Br @ dley写道:Cint(3/2)= 2(舍入起来,我原以为答案是1)
Cint(5/2)= 2(向下舍入)
Access帮助说Cint()向最近的偶数,但为什么?
我是否需要自己滚动整数转换让它总是向上舍入
或者下来?
我看着Cint(3 \2)和Cint(5 \2)这似乎一直是圆形的>下来......可能会这样做。
格式(3/2) - > 1.5一个字符串。要获得数字,请使用Val(格式(3/2))。
Int(格式(3/2)) - > 1. Int()删除小数。
格式(5/2) - > 2.5一个字符串。
Val(格式(5/2)) - > 2.5。 Int(格式(5/2)) - > 2.
-
MGFoster ::: mgf00< at> earthlink< decimal-point> net
奥克兰,加利福尼亚州(美国)
公共功能天花板(ByVal d As Double)As Long
天花板= - (Int(-d))
结束函数
MGFoster写道:Br @dley写道:Cint(3/2)= 2(四舍五入,我原以为答案是
1)Cint(5/2)= 2(向下舍入)
Access帮助说Cint()舍入到最近的偶数,但
为什么?我需要自己滚动吗?整数转换让它始终向上或向下舍入?
我看着Cint(3 \2)和Cint(5 \2)似乎一直在圆形>下来......可能会这样做。
格式(3/2) - > 1.5一个字符串。得到一个数字使用Val(格式(3/2))。
Int(格式(3/2)) - > 1. Int()删除小数。
格式(5/2) - > 2.5字符串。
Val(格式(5/2)) - > 2.5。 Int(格式(5/2)) - > 2。
Ta。我想我的主要问题是为什么Cint()轮到最近的偶数
数?只是对这种方式的实施感兴趣。
-
问候,
Br @ dley
Cint(3/2) = 2 (rounded up, I would have thought the answer would be 1)
Cint(5/2) = 2 (rounded down)
The Access help says Cint() rounds to the nearest even number, but why??
Do I need to "roll my own" integer conversion to get it to always round up
or down?
I looked at Cint(3\2) and Cint(5\2) which seems to consistently round
down... that may do.
--
regards,
Br@dley
Br@dley wrote:Cint(3/2) = 2 (rounded up, I would have thought the answer would be 1)
Cint(5/2) = 2 (rounded down)
The Access help says Cint() rounds to the nearest even number, but why??
Do I need to "roll my own" integer conversion to get it to always round up
or down?
I looked at Cint(3\2) and Cint(5\2) which seems to consistently round
down... that may do.
Format(3/2) -> 1.5 a string. To get a number use Val(Format(3/2)).
Int(Format(3/2)) -> 1. Int() removes the decimal.
Format(5/2) -> 2.5 a string.
Val(Format(5/2)) -> 2.5. Int(Format(5/2)) - > 2.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Public Function Ceiling(ByVal d As Double) As Long
Ceiling = -(Int(-d))
End Function
MGFoster wrote:Br@dley wrote:Cint(3/2) = 2 (rounded up, I would have thought the answer would be
1) Cint(5/2) = 2 (rounded down)
The Access help says Cint() rounds to the nearest even number, but
why?? Do I need to "roll my own" integer conversion to get it to always
round up or down?
I looked at Cint(3\2) and Cint(5\2) which seems to consistently round
down... that may do.
Format(3/2) -> 1.5 a string. To get a number use Val(Format(3/2)).
Int(Format(3/2)) -> 1. Int() removes the decimal.
Format(5/2) -> 2.5 a string.
Val(Format(5/2)) -> 2.5. Int(Format(5/2)) - > 2.
Ta. I guess my main question was WHY the Cint() rounds to the nearest even
number?? Just interested in the reasoning for implementing it that way.
--
regards,
Br@dley
这篇关于将float转换为整数时舍入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!