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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:02:24+00:00 2026-05-27T21:02:24+00:00

Possible Duplicate: Why can't decimal numbers be represented exactly in binary? I am developing

  • 0

Possible Duplicate:
Why can't decimal numbers be represented exactly in binary?

I am developing a pretty simple algorithm for mathematics use under C++.

And I have a floating point variable named “step”, each time I finish a while loop, I need step to be divided by 10.

So my code is kind of like this,

float step = 1;
while ( ... ){
      //the codes
      step /= 10;
}

In my stupid simple logic, that ends of well. step will be divided by 10, from 1 to 0.1, from 0.1 to 0.01.

But it didn’t, instead something like 0.100000000001 appears. And I was like “What The Hell”

Can someone please help me with this. It’s probably something about the data type itself that I don’t fully understand. So if someone could explain further, it’ll be appreciated.

  • 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-27T21:02:25+00:00Added an answer on May 27, 2026 at 9:02 pm

    It is a numerical issue. The Problem is that 1/10 is a endless long number in binary and the successive apply of a division by 10 ends up with summing the error in each step. To get a more stable version you should multiply the divisor. But take care: the result is also not exact! You may want to replace the float with a double to minimize the error.

    unsigned int div = 1;
    while(...)
    {
        double step = 1.0 / (double)div;
        ....
        div *= 10;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why can't decimal numbers be represented exactly in binary? I am trying
Possible Duplicate: Why can't decimal numbers be represented exactly in binary? i get very
Possible Duplicate: Why can't decimal numbers be represented exactly in binary? When I enter
Possible Duplicate: Is JavaScript's Math broken? Why can't decimal numbers be represented exactly in
Possible Duplicate: Can I use a binary literal in C or C++? I am
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd
Possible Duplicate: How to format a decimal How can I limit my decimal number
Possible Duplicate: django - ordering queryset by a calculated field How can i use
Possible Duplicate: Why can't I unbox an int as a decimal? Okay, C#/.NET gurus,
Possible Duplicate: Can I use .NET 4.0 beta in Visual Studio 2008? Hot can

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.