0

Here is my code. I have a problem with the decimals when it comes to "temp /= 100.0".

montant = 61;
for (int i=0 ; i<7 ; i++)
{
    if (i != posCreancier)
    {
        temp = montant/7.0;                  (temp == 8.7142857142857135)
        temp *= 100;                         (temp == 871.42857142857133)
        temp += 0.5;                         (temp == 871.92857142857133)
        temp = floor(temp);                  (temp == 871.00000000000000)
        temp /= 100.0;                       (temp == 8.7100000000000009)  Wtf with that "9" appearing ?!?
        tabDettes[posCreancier][i] = temp;
    }
}
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

One of the "problems" with floating point is that many numbers can not be represented exactly as you have found out. It's due to the way floats/doubles are represented in memory. A full explanation is given here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.