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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:11:28+00:00 2026-06-14T00:11:28+00:00

When I run: for($o=1;$o<=655;$o++){ $r = $r+0.01; echo $r. ;} at some point I

  • 0

When I run:

for($o=1;$o<=655;$o++){
$r = $r+0.01;
echo $r." ";}

at some point I get:

...4.29 4.3 4.31 4.32 4.33 4.34 4.35 4.36 4.37 4.38 4.39 4.4
4.41 4.42 4.4299999999999 4.4399999999999 4.4499999999999
4.4599999999999 4.4699999999999 ...

But when I run:

for($o=1;$o<=5;$o+=0.01){
echo $o." ";
}

anomaly starts at:

4.34 4.35 4.36 4.37 4.38 4.3899999999999 4.3999999999999

Why is there a difference between the addition being part of the for loop, or within the for loop?

  • 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-14T00:11:29+00:00Added an answer on June 14, 2026 at 12:11 am

    Welcome to the wonders of rounding errors.

    0.01 is not exactly expressible as a finite binary fraction, so you’ll pick up rounding errors eventually if you add it repeatedly to another floating point number.

    The specific point at which you see the rounding error depends on how the binary expansion of the numbers involved play out to produce the rounding error.

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

Sidebar

Related Questions

I run command: sudo apt-get install phpmyadmin to install phpMyAdmin. Then I enter address:
Run jsLint on this fiddle . The script runs, but what is jsLint telling
I run Selenium tests with Selenium RC from .NET (c#). In some cases, I
So I'm trying to get MySQL setup with python. I run sudo easy_install mysql-python
Run the following in Windows: java -version:1.5+ echo %ERRORLEVEL% If you run it with
Run this at a KornShell (ksh): echo ${MYVAR} | sed 's/\//\\/g' It works fine
run(/test.js) in mongo shell. i always get error run(/test.js) shell: started program /test.js sh2516|
I run this query: SHOW INDEX FROM `tbl_clients` I get back these: Table, Non_unique,
I run passenger with nginx and some months ago I deleted an nginx log
Can some one please assist me, I have homework due tonight but have one

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.