Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 529
user569125 Avatar asked Jan 18 '11 18:01

user569125


People also ask

How do you check if a value is an integer or not?

The Number. isInteger() method returns true if a value is an integer of the datatype Number. Otherwise it returns false .

How do you check if a variable is a float?

The is_float() function checks whether a variable is of type float or not. This function returns true (1) if the variable is of type float, otherwise it returns false.


1 Answers

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

like image 108
Alex Avatar answered Oct 03 '22 10:10

Alex