Unwanted division operator behavior, what should I do?
<h1>Problem description</h1>

<p>During my fluid simulation, the physical time is marching as <code>0, 0.001, 0.002, ..., 4.598, 4.599, 4.6, 4.601, 4.602, ...</code>. Now I want to choose time = <code>0.1, 0.2, ..., 4.5, 4.6, ...</code> from this time series and then do the further analysis. So I wrote the following code to judge if the <code>fractpart</code> hits zero.</p>

<p>But I am <strong>so surprised</strong> that I found the following two division methods are getting two different results, what should I do? </p>

<pre><code>double param, fractpart, intpart;
double org = 4.6;
double ddd = 0.1;

// This is the correct one I need. I got intpart=46 and fractpart=0
// param = org*(1/ddd);

// This is not what I want. I got intpart=45 and fractpart=1
param = org/ddd;

fractpart = modf(param , &amp;intpart);
Info&lt;&lt; "\n\nfractpart\t=\t"
    &lt;&lt; fractpart
    &lt;&lt; "\nAnd intpart\t=\t"
    &lt;&lt; intpart
    &lt;&lt; endl;
</code></pre>

<p>Why does it happen in this way?<br>
And if you guys tolerate me a little bit, can I shout loudly: "Could C++ committee do something about this? Because this is confusing." :)</p>

<p>What is the best way to get a correct remainder to avoid the cut-off error effect? Is fmod a better solution? Thanks</p>

<h1>Respond to the answer of</h1>

<p><strong>David Schwartz</strong></p>

<pre><code>double aTmp = 1;
double bTmp = 2;
double cTmp = 3;
double AAA = bTmp/cTmp;
double BBB = bTmp*(aTmp/cTmp);
Info&lt;&lt; "\n2/3\t=\t"
    &lt;&lt; AAA
    &lt;&lt; "\n2*(1/3)\t=\t"
    &lt;&lt; BBB
    &lt;&lt; endl;
</code></pre>

<p>And I got both ,</p>

<pre><code>2/3     =       0.666667
2*(1/3) =       0.666667
</code></pre>
