如何检查一个float是否有一个整数值 [英] How to check whether a float has an integer value
本文介绍了如何检查一个float是否有一个整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查输入值是整数还是浮点数?
假设312/100 = 3.12,这里我需要检查3.12是float还是integer。
解决方案
您应该检查小数部分的数字是0.
使用
x == Math.ceil(x)
或
x == Math.round(x)
或类似的东西
How to check whether input value is integer or float?
Suppose 312/100=3.12,Here i need check whether 3.12 is float or integer.
解决方案
You should check that fractional part of the number is 0. Use
x==Math.ceil(x)
or
x==Math.round(x)
or something like that
这篇关于如何检查一个float是否有一个整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文