Android 大实数之和是整数而不是实数
我创建了一个包含一些值的表:Android 大实数之和是整数而不是实数,android,sqlite,floating-point,sum,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
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,我不明白为什么
如果我不输入大的数字,它可以正常工作,但是对于大的数字,我只得到结果的整数部分。我觉得这些数字看起来不太大。为什么不使用getDouble而不是getString?当它是double时,为什么
getString()
?为什么if(cursor.moveToFirst()){do{}while(cursor.moveToNext())