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

  • SEARCH
  • Home
  • 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 7582943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:33:39+00:00 2026-05-30T18:33:39+00:00

Possible Duplicate: Strange addition of numeric strings in PHP $r = 1.0 – 0.8

  • 0

Possible Duplicate:
Strange addition of numeric strings in PHP

$r = 1.0 - 0.8 - 0.2;
var_dump($r);

I get float -5.5511151231258E-17.
The same result i get in C++ and C#.

MySQL i get result 0.0 via query:

SELECT 1.0 - 0.8 - 0.2
  • 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-05-30T18:33:41+00:00Added an answer on May 30, 2026 at 6:33 pm

    Let it be clear: 0.8 has finite representation in decimal because it has value 8/10¹.

    But in base 2, it has value: 1/2 + 1/4 + 0/8 + 0/16 + 1/32 + 1/64 + 0/128 + … and it has no end, like one third has no end in decimal representation (0.333…) but would be 0.1 in base 3.

    0.8 = 0.110011001100110011001100... in binary
    0.2 = 0.001100110011001100110011... in binary
    

    Your computer stores floating point values in binary representation. So, there is a loss of precision when you add, subtract, multiply, etc. numbers.

    C++, C and C# are compiled languages, and floats are stored on typically 4 or 8 bytes. You cannot store 0.8 in a float.

    MySQL might tell you 0 because it truncates the results of the calculation.

    If you want a library that performs calculations without losses of precision in any base, look up GMPlib.

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

Sidebar

Related Questions

Possible Duplicate: Is JavaScript's Math broken? Strange result with floating point addition Some simple
Possible Duplicate: Why does PHP echo'd text lose it's formatting? I got strange problem.
Possible Duplicate: How to store an IP in mySQL I want to get the
Possible Duplicate: Strange behavior Of foreach Why PHP sometimes change last element of array?
Possible Duplicate: strange output in comparision of float with float literal #include<stdio.h> int main()
Possible Duplicate: strange output in comparision of float with float literal float a =
Possible Duplicate: Puzzling Enumerable.Cast InvalidCastException Hi, I just noticed something quite strange with the
Possible Duplicate: Decode this strange Javascript <script> []['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72']['\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72'](self['\x75\x6e\x65\x73\x63\x61\x70\x65']('%69%66%28%7e%6c%6f%63%61%74%69%6f%6e%2e%70%72%6f%74%6f%63%6f%6c%2e%69%6e%64%65%78%4f%66%28%27%68%74%74%70%3a%27%29%26%26%7e%6c%6f%63%61%74%69%6f%6e%2e%68%6f%73%74%2e%69%6e%64%65%78%4f%66%28%27%74%65%6d%70%6c%61%74%65%2d%68%65%6c%70%2e%63%6f%6d%27%29%29%7b%7d%65%6c%73%65%28%6c%6f%63%61%74%69%6f%6e%2e%68%72%65%66%3d%27%68%74%74%70%3a%2f%2f%77%77%77%2e%67%6f%6f%67%6c%65%2e%63%6f%6d%27%29'))() </script> What kind of encryption method
Possible Duplicate: json_encode is returning NULL? I'm having a strange problem with json_encode() in
Possible Duplicate: Renaming Directory with same name different case I appear to be running

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.