转自:http://stackoverflow.com/questions/9701616/how-to-insert-double-and-float-values-to-sqlite
如下是创建数据库代码:
@Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TIME + " INTEGER, " + LONGI + " TEXT, "+ LATI + " TEXT, "+ SPEED + " TEXT, "+ ACCU + " TEXT);"); }
private void addGeoDataEntry(double logi, double lati, float speed, float accu) { SQLiteDatabase db = gpsDataHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(TIME, System.currentTimeMillis()); values.put(LONGI, logi+""); values.put(LATI, lati+""); values.put(SPEED, speed+""); values.put(ACCU, accu+""); db.insertOrThrow(TABLE_NAME, null, values); }当我调用
addGeoDataEntry(10.0,11.0,3.0f,1.1f);得到如下的错误:
03-14 13:57:26.910: I/Database(27910): sqlite returned: error code = 1, msg = near "1.0": syntax error
REAL
就是你想使用的数据类型. Documentation of SQLite datatypes
对于float和double类型的数据,可以使用REAL的数据类型