在 VB.NET 中四舍五入到整数
我有这样的代码:
Dim minutes As Integer = (55 / 60)
我希望它返回 0 给我,整数 0(无小数),但 VB.NET 将其舍入为 1。
我该如何完成此操作?
对于那些有同样问题的人来说,尝试用 \
除(是的,它不是 VB.NET 中的转义字符)。
I have code like this:
Dim minutes As Integer = (55 / 60)
I want this to return 0 to me, integer 0 (no decimals), but VB.NET rounds this to 1.
How do I accomplish this?
OK for those with the same problem, try dividing with \
(yeah, it's not escape character in VB.NET).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于完整的十进制除法,您必须使用另一个运算符。
尝试:
For full decimal division you have to use another operator.
Try:
Dim 分钟 As Integer = Math.Round(55 / 60)
有一些重载允许舍入为小数值,并指定如果该值恰好位于两个整数之间则舍入的方式。
Dim minutes As Integer = Math.Round(55 / 60)
There are overloads that allow rounding to fractional values and specifying which way to round if the value is exactly between two integers.
那么向下吗?使用:
So round down? Use: