How to correct the decimal fractions?
<pre><code>#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string&gt;
#include &lt;iomanip&gt;
#include &lt;cmath&gt;

using namespace std;
void toBase (int n, int base)
{
    string x = "0123456789ABCDEF";
    if (n &gt; 0)
    {
      toBase(n / base, base);
        cout &lt;&lt; x[n % base];
    }
}

int main()
{

    float num;
    int a;
    cout &lt;&lt; "";
    cin &gt;&gt; num;
    cout &lt;&lt; "";
    cin &gt;&gt; a;
    toBase(num, a);
    cout &lt;&lt; ".";
    float fNum = 12.34;
    int iPart = (int)fNum;
    float fPart = fNum - (float)iPart;
    toBase(fNum, a);
    cout &lt;&lt; endl;


    }
</code></pre>

<p>I posted a similar question before, and here i am again. I just can't get the decimal fractions to work. I tried multyplying by 2, but it didn't work, i'm not very good at this so i'm hoping for some help. Anyways, i'm supposed to create a code that converts decimal numbers (with decimal fractions) into other bases (from 2 to 16) - So far, only 2 of the 10 test results are correct.</p>

<pre><code>10.5 - 1010.1 - 1010.1100   
2      
3.827 - 10.2110222122 - 10.110   
3     
82.7593 - 101.6744681322 - 101.13    
9     
7218.8192 - 5472.90139A8535 - 5472.11    
11     
8273.8 - 26B8.C - 26B8.C    
15     
23517.75 - 5BDD.C - 5BDD.C
16    
92.33271 - 1011100.0101010100 - 1011100.1100
2     
4095.839 - 7777.6554426416 - 7777.14    
8     
29672.9311 - 13033220.3232113021 - 13033220.30    
4     
9999.987 - 270F.FCAC083126 - 270F.C    
16
</code></pre>

<p>As you can see, the numbers before the dot are always correct, but the decimal fractions (except in two cases) are always wrong. (10.5 and 2 are the decimal numbers and the base, the second number is what i should get, the third number is what i get).</p>
