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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:11:09+00:00 2026-06-11T19:11:09+00:00

I am a programming newbie. I needed a simple function to convert any number

  • 0

I am a programming newbie. I needed a simple function to convert any number with decimal point X.YZ into XYZ. I did it by multiplying it by 10 enough times and using double to int conversion.


  int main()
  {
    std::cout << "Number: " << std::endl;
    double a;
    // the uninitialized b was pointed out, its not the issue
    long b = 0;

    std::cin >> a;

       while(b!=a)
             {
              a*=10;
              b=a;
             }

    std::cout << a << std::endl;
    return 0;
  }

This works like 90 percent of the time. For some numbers like 132.54, the program runs infinitely long. It processes 132.547(which should use more memory then 132.54) the way it should.

So my question is : Why is it not working 100 percent for the numbers in the memory range of long int? Why 132.54 and similar numbers?

I am using Codeblocks and GNU GCC compiler.

  • 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-11T19:11:10+00:00Added an answer on June 11, 2026 at 7:11 pm

    Many decimal floating point numbers cannot be exactly represented in binary. You only get a close approximation.

    If 132.54 is represented as 132.539999999999999, you will never get a match.

    Print the values in the loop, and you will see what happens.

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

Sidebar

Related Questions

I'm a programming newbie, and I can't figure out how to store a function
I'm newbie to Game programming. I'm trying to develop a simple shooting game. The
I am a newbie to the programming world. I have experiences of developing simple
I am newbie to programming and I am trying to pass an array into
I'm a socket programming newbie. Here's a snippet: struct sockaddr_storage client_addr; ... client_addr_size =
I am complete newbie for programming and this is my first real program I
I am newbie for iOS programming. I'm trying to create an array of arrays
I'm a newbie in php programming and i can't make it finding where is
I am an absolute newbie to Perl as well as programming in general(less than
I'm kind of a newbie to objective programming, so sorry for the dumb question.

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.