math.floor 应该返回整数 [英] math.floor is supposed to return integer

查看:34
本文介绍了math.floor 应该返回整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个变量相除后得到一个数的整数部分.即,如果值为 3.75,则为 3displaycount 和 itemcount 都是整数变量.

I am trying to get the integer part of a number after dividing two variables. ie, get 3 if the value is 3.75 displaycount and itemcount are both integer variables.

    Dim cntr As Integer        
    cntr = Math.Floor(Math.Abs(itemCount / displaycount))

该代码在 VS2012 中产生蓝色波浪线,注释为将 Double 转换为整数时可能会出现运行时错误",但 Math.Floor 应该采用小数或双精度并返回整数.

That code produces a blue squiggly in VS2012 with the comment that "runtime errors may occur when converting Double to Integer" BUT Math.Floor is supposed to take a decimal or double and return an integer.

推荐答案

Math.Floor 应该采用小数或双精度并返回一个整数."不,不是.它返回一个与其参数相同类型的值.请参阅文档,例如Math.Floor 方法(双).

"Math.Floor is supposed to take a decimal or double and return an integer." No, it isn't. It returns a value of the same type as its argument. See the documentation, e.g. Math.Floor Method (Double).

我本来希望 VS 建议在分配的 RHS 周围添加 CInt() 的修复程序;你没有看到吗?

I would have expected VS to suggest a fix of adding CInt() around the RHS of the assignment; did that not appear for you?

这篇关于math.floor 应该返回整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆