Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

How do I perform integer division in PHP

Olivia Rhye

PHP's division operator returns a floating point result from the division operator unless both operands are integers and they are evenly divisible (the result is an integer).  I was recently working on Project Euler Problem 13 and needed to do integer division, something I haven't come across in PHP before.  

Integer division in PHP is pretty straight forward.  Casting the result as an integer will yield an integer.  That is:

var_dump(25/7); // float(3.5714285714286)
var_dump((int) (25/7)); // int(3)
var_dump(round(25/7));  // float(4)

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy