Reputation: 11782
I am using following code
public boolean addArea(AreaClass area , ArrayList<AreaMarkClass> areaArray)
{
area.id = getNextAreaId();
Log.d("longitude", area.longitude);
Log.d("latitude", area.latitude);
ContentValues initialValues = new ContentValues();
initialValues.put("_id", area.id);
initialValues.put("name", area.name);
initialValues.put("longitude", area.longitude);
initialValues.put("latitude", area.latitude);
initialValues.put("zoomLevel", area.zoomLevel);
initialValues.put("creationDate",area.creationDate);
try
{
mDb.insertOrThrow("TTArea", null, initialValues);
}
area.longitude
is a string whose value is obtained by String.value
(A Double Value)
Now usually it is something like this 22.323434523464563456
however when i try to retrieve this value
public AreaClass getAreaClassWithAreaId(Integer id)
{
String queryString = "SELECT * FROM TTArea WHERE _id = ?";
Cursor resultSet = mDb.rawQuery(queryString, new String[]{id.toString()});
AreaClass area = new AreaClass();
while(resultSet.moveToNext())
{
area = new AreaClass(
resultSet.getInt(resultSet.getColumnIndex("_id")),
resultSet.getString(resultSet.getColumnIndex("name")),
resultSet.getString(resultSet.getColumnIndex("longitude")),
resultSet.getString(resultSet.getColumnIndex("latitude")),
resultSet.getString(resultSet.getColumnIndex("zoomLevel")),
resultSet.getString(resultSet.getColumnIndex("creationDate"))
);
}
resultSet.close();
return area;
}
it somehow rounds it to 22.3234
. In my app i need precise what i am storing. What is this behavior and how can i resolve this?
Upvotes: 0
Views: 1133
Reputation: 478
I use these methods when working with SQLite:
public static Double stringToDouble (String x)
{
if (x !=null)
return Double.parseDouble(x);
return null;
}
public static String doubleToString (Double y)
{
if (y != null)
return String.valueOf(y);
return null;
}
When adding to database transform the double value to string and vice-versa, and please tell me if this solution works
EDIT: The solution is in comments: "I see you created your table with STRING fields. You can try with TEXT type, works for me."
Upvotes: 2