Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:10:33+00:00 2026-06-12T15:10:33+00:00

In languages like C or Python 2, if I divide an integer by an

  • 0

In languages like C or Python 2, if I divide an integer by an integer, I get an integer:

>>> 8/3
2

But in PHP, if I divide an integer by another integer with /, sometimes I get a float:

php > var_dump(6/3);
int(2)
php > var_dump(8/3);
float(2.6666666666667)

I’d like to do division like in Python or C, so that 8/3 is 2. How can I do that in PHP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:10:34+00:00Added an answer on June 12, 2026 at 3:10 pm

    As of PHP 7, we can use the intdiv built-in function to get an integer value:

    intdiv(8,3); // 2
    

    For earlier versions of PHP, we can use the round() function to get an integer rounded value:

    round(8 / 3); // 3
    

    Or we can use the floor() function to get an integer value:

    floor(8 / 3); // 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in languages like PHP or Python there are convenient functions to turn an input
This is simple to do in languages like Python, but I'm not sure how
I have few experience with languages like Python, Perl and Ruby, but I have
Let's define languages like c,c++,java as code Python,PHP as script. Is c# code or
When I speak of scripting languages I am speaking of languages like Python, Perl,
Basically, I want to do something like this (in Python, or similar imperative languages):
I am experimenting with several languages (Python, Ruby...), and I would like to know
I think that some newer languages like JS can do this natively, but I
Consider languages like Python or JavaScript that allow functions to be nested like this:
Some popular languages like Python and Ruby have native, JVM and .Net CLR implementations.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.