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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:32:23+00:00 2026-05-22T11:32:23+00:00

Hey so I’m making a function that returns the number of decimals, whole numbers,

  • 0

Hey so I’m making a function that returns the number of decimals, whole numbers, or TOTAL numbers there are, but have been unable to make it work with either of these ways:

  • multiplying by a really large number like 10 billion doesn’t work because of the innacurate way computers store decimals, making 2.3 2.2999575697

  • Using a StringStream to convert the number to a string and count the characters doesn’t work because it requires you to set the stream to a precision which either takes away or adds unnecesary ‘0’ characters if not set to the actual number of decimals

So WHAT DO I DO NOW? somebody please help =( Thanks!

if you wanna see my function that converts the numb to a string here it is:

//////////////////////      Numbs_Digits    ////////////////////////////////////////////////
template<typename T>
int Numbs_Digits(T numb, int scope)
{
    stringstream ss(stringstream::in| stringstream::out), ss2(stringstream::in| stringstream::out);
        unsigned long int length= 0;
        unsigned long int numb_wholes;
                          ss2 << (int)numb; 
                          numb_wholes = ss2.str().length(); ss2.flush();
        bool all= false;
        ss.precision(11);   // HOW DO I MAKE THE PRECISION NUMBER THE NUMBER OF DECIMALS?

    switch(scope){
        case ALL:        all = true;

        case DECIMALS:   ss << fixed << numb;
                         length += ss.str().length()- (numb_wholes +1); // +1 for the "."
                         if(all!= true) break;

        case WHOLE_NUMBS: 
                         length += numb_wholes;
                         if(all!= true) break;

        default: break;}

        return length;};
  • 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-22T11:32:23+00:00Added an answer on May 22, 2026 at 11:32 am

    Only some decimal numbers can be stored in exact form as a floating point number. Because of this there is no way to determine how many decimal places are significant for any decimal number for which this is not true. As hammar suggested, read up on the floating point storage format, I believe that every programmer should have some knowledge of low level stuff like this 😀

    multiplying by a really large number like 10 billion doesn’t work because of the innacurate way computers store decimals, making 2.3 2.2999575697

    This is exactly the problem. Would you be able to look at 2.999575697 and tell me it has two decimal places? This number is an example of a decimal number that cannot be stored in exact form using the floating point format. The best you could do is count the significant decimal places stored in the floating point number that best approximates the original decimal number it was given – which I can’t imagine would be much use.

    Edited for a more accurate explanation.

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

Sidebar

Related Questions

Hey everyone I have a basic search function here that allows me to search
Hey just curious is there a function that you can use to divide in
Hey I have an array with numbers in it. Now I want to divide
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey so I've been searching around for this topic and couldn't find a whole
Hey I thought about writing a function that prompts me in certain situations (perl
Hey guys I have my script here that is supposed to do some stuff
Hey all i have an XML file that i am trying to loop though.
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Hey I have been given an essay to write about Processes and threads in

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.