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 8745617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:03:37+00:00 2026-06-13T12:03:37+00:00

I resolved the issue with the code that i was working, but this is

  • 0

I resolved the issue with the code that i was working, but this is something that bugs me out.

I know that floating point in certain circumnstances just messes up with rounding.
I know that php uses types inferences, and there is an automatic cast when you operate aritmetically between strings (i mean, in this particular case, in my example).

Doing the same thing ‘by hand in code’, result of 160.2 * 50 is 8010, when there is no need for rounding when casting to the integer result. Is just ackward.
If anyone knows why this happens, it will enlightment me.

echo "160.2" * "50"; // gives 8010
echo (int) ((float)"160.2" * (int)"50"); // Gives 8009

I solved the issue and my code is working now; this is just for fun. I want to know why and how, step by step php messes up with this. Where is php losing resolution? In what step?

Thanks in advance 🙂

  • 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-13T12:03:38+00:00Added an answer on June 13, 2026 at 12:03 pm

    PHP represented (float)"160.2" as the binary equivalent of 160.19999999995343387126... internally. That would cause the multiplication result to be slight smaller than 8010, which on casting back to int, causes truncation and leads to 8009

    160.2 in binary cannot be perfectly represented. It comes out to be a recurring decimal,

    10100000.00110011001100110011001100110011...
    

    So you cannot expect it to be accurately represented with float.

    (Converter)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I resolved this issue myself. It turns out that the activation framework requires some
I resolved a code issue with a gem, but how do I then use
I previously had a post on this issue that was resolved. However since rebuilding
I know that this particular topic was asked many times, but unfortunately in my
I've come across an issue with ActiveResource that has been resolved and was trying
I can't resolve this issue, I found a similar question here but: setting the
This answer has helped me largely but hasn't fully resolved my issues. I'm using
I'm having a strange issue that I can't seem to figure out. I tried
I know this is similar to many other questions on S.O. but none of
I've got a bit of code that I've been working on for a friend

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.