Search code examples
androidinfinity

Android cursor c.getFloat() return Infinity


I've changed from eclipse to android studio few days ago.

Now I've found this weird bug.

if(c.moveToFirst())
                {
                    do
                    {
                        exchange_rate = c.getFloat(columnExRate);
                        if(exchange_rate > 0)
                            total = total + c.getFloat(columnValue) * exchange_rate;
                        else
                            total = total + c.getFloat(columnValue);
                    }while(c.moveToNext());
                }

Sometimes exchange_rate is equal to Infinity.

enter image description here

This happened at the second loop only in a specific set of data.

Maybe it's because I've entered the exchange_rate like a double and the I read a float?


Solution

  • Solved.

    I've saved 1 / exchange_rate value without checking if exchange_rate is equal or not to 0.

    1 / 0 return Infinity.