大实数的和是整数而不是实数

时间:2013-03-14 10:25:55

标签: android sqlite floating-point sum

我创建了一个包含一些值的表:

db.execSQL("create table table_test ("
                + "id integer primary key autoincrement," 
                + "money real not null" + ");");

ContentValues cv;
cv = new ContentValues();
cv.put("money", "137.38");
db.insert("table_test", null, cv);

cv = new ContentValues();
cv.put("money", "136975.00");
db.insert("table_test", null, cv);

然后我试图获得一笔钱:

cursor = db.query("table_test", new String[] { "total(money) as money" }, null, null, null, null, null);
    if (cursor.moveToFirst()) {
      do {
        String money = cursor.getString(cursor.getColumnIndex("money"));
        Log.d(tag, "money=" + money);
      } while (cursor.moveToNext());
    }
cursor.close();

答案应该是137112.38,但它将其更改为137112 - 我不明白为什么。

如果我不输入大数字它可以正常工作,但是大数字我只得到结果的整数部分。

0 个答案:

没有答案