# Php, How To Convert A String Into Number In Php

Summary: in this tutorial, you’ll learn about the PHP int type that represents integers in PHP.

Bạn đang xem: Php, how to convert a string into number in php

## Introduction to lớn the PHP int type

Integers are whole numbers such as -3, -2, -1, 0, 1, 2, 3… PHP uses the int type to lớn represent the integers.

The range of integers depends on the platform where PHP runs. Typically, integers has a range from -2,147,438,648 khổng lồ 2,147,483,647. It’s equivalent to 32 bits signed.

To get the size of the integer, you use the PHP_INT_SIZE constant. Also, you use the PHP_INT_MIN & PHP_INT_MAX constants khổng lồ get the minimum & maximum integer values.

PHP represents integer literals in decimal, octal, binary, và hexadecimal formats.

### Decimal numbers

PHP uses a sequence of digits without leading zeros to lớn represent decimal values. The sequence may begin with a plus or minus sign. If it has no sign, then the integer is positive. For example:

2000-10012345
From PHP 7.4, you can use the underscores (_) to lớn group digits in an integer lớn make it easier to read. For example, instead of using the following number:

1000000
you can use the underscores (_) to lớn group digits lượt thích this:

1_000_000

### Octal numbers

Octal numbers consist of a leading zero & a sequence of digits from 0 khổng lồ 7. Like decimal numbers, the octal numbers can have a plus (+) or minus (-) sign. For example:

+010 // decimal 8
Code language: JavaScript (javascript)

Hexadecimal numbers consist of a leading 0x và a sequence of digits (0-9) or letters (A-F). The letters can be lowercase or uppercase. By convention, letters are written in uppercase.

Similar to decimal numbers, hexadecimal numbers can include a sign, either plus (+) or minus(-). For example:

0x10 // decimal 160xFF // decimal 255
Code language: JSON / JSON with Comments (json)

### Binary numbers

Binary numbers begin with 0b are followed by a sequence of digits 0 & 1. The binary numbers can include a sign. For example:

0b10 // decimal 2
Code language: JavaScript (javascript)

## The is_int() function

The is_int() built-in function returns true if a value (or a variable) is an integer. Otherwise, it returns false. For example:

\$amount = 100;echo is_int(\$amount);
Code language: PHP (php)Output:

1

## Summary

Integers are whole numbers such as -1, 0, 1, 2…Use the PHP_INT_SIZE constant to get the size of the integerUse the PHP_INT_MIN & PHP_INT_MAX constants to lớn get the minimum & maximum integer values.Literal integers can be in decimal, octal, hexadecimal, & binary forms.Use the is_int() function returns true if a value (or variable) is an integer.
Did you find this tutorial useful?
Yes No

Previously
PHP Boolean
Up Next
PHP float

search for: