YogeshChauhan . com

How to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?

in PHP on November 19, 2019

PHP provides auto data type conversion so you can assign int value in the beginning and change it to float in the middle and PHP won't make a sound!

An integer data type is a non-decimal number between -2147483648 and 2147483647. So, any number out of that range is considered and stored as a float.

So, we need to be careful while assigning values in a lengthy program or calculation as the data type change can cause some errors. 

Here are the functions we can use to check if the number is integer.

  • is_int()
  • is_integer() 
  • is_long()

To check whether the number is float use these following functions:

  • is_float()
  • is_double()

Now, the float has it's own limit as well. If the number is greater than the PHP_FLOAT_MAX than it's infinite number. We can check that using following functions.

  • is_finite()
  • is_infinite()

To check whether the value is not a number, use this

  • is_nan()

Lastly, to check whether the variable is numeric or not, use following function

  • PHP is_numeric()
amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to Block IPs and User Agents using code in Drupal or WordPress?DrupalA Quick Comparison of JOIN and Subquery in SQLSQL/MySQLHow to Use SQL MAX() Function with Dates?SQL/MySQLHow to use Context in React?ReactUse inline if to make a shorter conditional syntax in ReactReactWhat does Containment mean in React?ReactSolution to pod install fails with json error on Mac OS X 10.15 (or Mac OS Catalina)MiscConfiguring Modules with @forward rule in SCSS (Sass)SCSSNew to ┬áDrupal? Here’s What You Need to KnowDrupalThe Complete Basic Explanation of PHP SessionsPHPAdvanced Array Methods in JavaScript (with examples)JavaScriptCreate a simple bar chart and column chart using pure CSS gridCSS