在 VB.NET 中四舍五入到整数

发布于 2024-12-04 06:25:47 字数 215 浏览 2 评论 0原文

我有这样的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与酒说心事 2024-12-11 06:25:47

对于完整的十进制除法,您必须使用另一个运算符。

尝试:

\

For full decimal division you have to use another operator.

Try:

\
左秋 2024-12-11 06:25:47

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.

软的没边 2024-12-11 06:25:47

那么向下吗?使用:

?Math.Truncate(55/60)
0.0

So round down? Use:

?Math.Truncate(55/60)
0.0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文