How to divide an integer by an integer in php

藏色散人
Release: 2023-03-10 17:20:02
Original
1782 people have browsed it

In PHP, you can use the arithmetic operator "/" to divide an integer by an integer. The division operator always returns a floating point number. Only when both operands are integers and can be divided exactly, then It returns an integer.

How to divide an integer by an integer in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

How does php divide an integer by an integer?

$a / $bDivision The quotient of $a divided by $b.

$a % $bTakes the remainder modulo $a divided by $b.

The division operator always returns a floating point number. The only exception is that both operands are integers (or integers converted from strings) and are exactly divisible, in which case it returns an integer. For integer division, please refer to intdiv().

The operands of the modulo operator will be converted to integers (except for the decimal part) before operation. For floating point number modulus, please refer to fmod().

The result of the modulo operator % is the same as the sign (positive or negative sign) of the dividend. That is, the result of $a % $b has the same sign as $a. For example:

Copy after login

Recommended: "PHP Video Tutorial"

The above is the detailed content of How to divide an integer by an integer in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!