本文介绍了检查数字是否是Java中的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何方法或快速方法可以检查数字是否是Java中的整数(属于Z字段)?
Is there any method or quick way to check whether a number is an Integer (belongs to Z field) in Java?
我想可能从中减去它舍入的数字,但我没有找到任何方法可以帮助我。
I thought of maybe subtracting it from the rounded number, but I didn't find any method that will help me with this.
我应该在哪里检查?整数Api?
Where should I check? Integer Api?
推荐答案
又快又脏......
Quick and dirty...
if (x == (int)x)
{
...
}
编辑:假设x已经是其他数字形式。如果您正在处理字符串,请查看 Integer.parseInt
。
edit: This is assuming x is already in some other numeric form. If you're dealing with strings, look into Integer.parseInt
.
这篇关于检查数字是否是Java中的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!