Search code examples
javafloating-pointintrounding

How to check whether input value is integer or float?


How to check whether input value is integer or float?

Suppose 312/100=3.12 Here i need check whether 3.12 is a float value or integer value, i.e., without any decimal place value.


Solution

  • 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