【问题标题】:Restrict a formula result to an int? [duplicate]将公式结果限制为 int? [复制]
【发布时间】:2016-11-09 15:44:03
【问题描述】:

我有一个公式,当结果是整数(不是浮点数、双精度数或其他数字类型)时,应该考虑它。那么……有没有可能说:“如果结果不是整数,那么……”?

【问题讨论】:

  • 你有返回int的方法吗?然后你不能有任何其他类型的变量......你应该edit显示一些代码
  • 1000 * 0.001 不一定会产生 1.0 并且等于 1。所以:if (Math.abs(x - Math.round(x)) < 1E-14) { intish }

标签: java integer


【解决方案1】:
 if(obj instanceof Integer) { 
     //this should do the job 
 }

【讨论】:

  • 啊,太好了,这行得通!非常感谢。
猜你喜欢
  • 2013-12-05
  • 2019-11-12
  • 2013-11-13
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-22
相关资源
最近更新 更多