Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to figure out how many decimal digits are in a large double?
    primarykey
    data
    text
    <p>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:</p> <ul> <li><p><strong>multiplying by a really large number</strong> like 10 billion doesn't work because of the innacurate way computers store decimals, making 2.3 2.2999575697</p></li> <li><p>Using a <strong>StringStream</strong> 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</p></li> </ul> <p>So WHAT DO I DO NOW? somebody please help =( <strong>Thanks!</strong></p> <p>if you wanna see my function that converts the numb to a string here it is:</p> <pre><code>////////////////////// Numbs_Digits //////////////////////////////////////////////// template&lt;typename T&gt; 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 &lt;&lt; (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 &lt;&lt; fixed &lt;&lt; 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;}; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload