Need floating point precision, GUI gui uses int
<p>I have a flow layout. Inside it I have about 900 tables. Each table is stacked one on top of the other. I have a slider which resizes them and thus causes the flow layout to resize too.</p>

<p>The problem is, the tables should be linearly resizing. Their base size is 200x200. So when scale = 1.0, the w and h of the tables is 200.</p>

<p>I resize by a fixed amount each time making them 4% bigger each time. This means I would expect them to grow by 8 pixels each time. What happens is, every few resizes, the tables grow by 9 pixels. I use doubles everywhere. I have tried rounding, floor and ceil but the problem persists. What could I do so that they always grow by the correct amount?</p>

<pre><code>void LobbyTableManager::changeTableScale( double scale )
    {
        setTableScale(scale);
    }

    void LobbyTableManager::setTableScale( double scale )
    {
        scale += 0.3;
        scale *= 2.0;

        std::cout &lt;&lt; scale &lt;&lt; std::endl;
        agui::Gui* gotGui = getGui();
        float scrollRel = m_vScroll-&gt;getRelativeValue();
        setScale(scale);
        rescaleTables();
        resizeFlow();
    ...



    double LobbyTableManager::getTableScale() const
        {
            return (getInnerWidth() / 700.0) * getScale();
        }

    void LobbyFilterManager::valueChanged( agui::Slider* source,int val )
    {
        if(source == m_magnifySlider)
        {

            DISPATCH_LOBBY_EVENT
            {
                (*it)-&gt;changeTableScale((double)val / source-&gt;getRange());
            }
        }
    }

void LobbyTableManager::renderBG( GraphicsContext* g, agui::Rectangle&amp; absRect, agui::Rectangle&amp; childRect )
    {
        int cx, cy, cw, ch;
        g-&gt;getClippingRect(cx,cy,cw,ch);
        g-&gt;setClippingRect(absRect.getX(),absRect.getY(),absRect.getWidth(),absRect.getHeight());
        float scale = 0.35f;
        int w = m_bgSprite-&gt;getWidth() * getTableScale() * scale;
        int h = m_bgSprite-&gt;getHeight() * getTableScale() * scale;

        int numX = ceil(absRect.getWidth() / (float)w) + 2;
        int numY = ceil(absRect.getHeight() / (float)h) + 2;

        float offsetX = m_activeTables[0]-&gt;getLocation().getX() - w;
        float offsetY = m_activeTables[0]-&gt;getLocation().getY() - h;
        int startY = childRect.getY() + 1;
        if(moo)
        {
            std::cout &lt;&lt; "TS: " &lt;&lt; getTableScale() &lt;&lt; " Scr: " &lt;&lt; m_vScroll-&gt;getValue() &lt;&lt; " LOC: " &lt;&lt; childRect.getY() &lt;&lt; " H: " &lt;&lt; h &lt;&lt; std::endl; 
        }
    if(moo)
    {
        std::cout &lt;&lt; "S=" &lt;&lt; startY &lt;&lt; ",";
    }
        int numAttempts = 0;
        while(startY + h &lt; absRect.getY() &amp;&amp; numAttempts &lt; 1000)
        {
            startY += h;
            if(moo)
            {
                std::cout &lt;&lt; startY &lt;&lt; ",";
            }

            numAttempts++;
        }


        if(moo)
        {
            std::cout &lt;&lt; "\n";
            moo = false;
        }
        g-&gt;holdDrawing();
        for(int i = 0; i &lt; numX; ++i)
        {
            for(int j = 0; j &lt; numY; ++j)
            {
                g-&gt;drawScaledSprite(m_bgSprite,0,0,m_bgSprite-&gt;getWidth(),m_bgSprite-&gt;getHeight(),
                    absRect.getX() + (i * w) + (offsetX),absRect.getY() + (j * h) + startY,w,h,0);
            }
        }
        g-&gt;unholdDrawing();
        g-&gt;setClippingRect(cx,cy,cw,ch);
    }

        void LobbyTable::rescale( double scale )
        {
            setScale(scale);
            float os = getObjectScale();
            double x = m_baseHeight * os;
            if((int)(x + 0.5) &gt; (int)x)
            {
                x++;
            }
            int oldH = getHeight();
            setSize(m_baseWidth * os, floor(x));
    ...
</code></pre>

<p>I added the related code. The slider sends a value changed which is multiplied to get a 4 percent increase (or 8 percent if slider moves 2 values etc...) then the tables are rescaled with this.</p>

<p><img src="http://i.stack.imgur.com/5lyPy.png" alt="enter image description here"></p>

<p>The first 3 are when the table size increased by 9, the 4th time it increased by 8px. But the scale factor increases by 0.04 each time.</p>

<p>Why is the 4th time inconsistant?</p>

<p>the pattern seems like 8,8,8,9,9,9,8,8,8,9,9,9...</p>

<p>It increases by 1 pixel more for a few and then decreases by 1 ten increases by 1 etc, thats my issue...</p>
