0

关于这个,我还是有点菜鸟。我对正在发生的事情感到困惑。我将 3.542 存储在 sqlite 数据库中。使用 Firefox sqlite 查看器检查数据库证实了这一点。然后我使用以下代码检索了该值:

public double getCaffPer(String type) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(DRKTYPES);
    String[] columns = { MGCAFF };
    String[] selectionArgs = { type };
    Cursor cursor;
    cursor = builder.query(ourDatabase, columns, TYPE + "=?",
            selectionArgs, null, null, null);
    float result = -1;
    if (cursor.getCount() != 0) {
        cursor.moveToFirst();
        result = cursor.getFloat(0);
    }
    cursor.close();
    return result;
}

调试显示结果值为 3.542。但后来在我的代码中,我调用了这个方法:

double caff = helper.getCaffPer(typeName);

它给了我 3.5420000553131104。我知道这没什么区别,但我很困惑为什么要添加最后的东西。任何帮助,将不胜感激。

4

1 回答 1

4

发生该行为是因为您声明result为 afloatgetCaffPer()返回 a double。Java 在这两种类型之间进行静默转换,这会在输出中引入差异。

于 2013-04-01T23:39:41.153 回答