I am trying to use custom TypeConverter for Android Room Persistance Library as shown in documentation. Main idea is to format all Sqlite SUM selects that Android Room Dao is preforming.
My code:
@TypeConverter
public static double toDouble(String str) {
return FormatHelper.formatAmount(Double.parseDouble(str));
}
@TypeConverter
public static String fromDouble(double doub) {
return String.valueOf(FormatHelper.formatAmount(doub));
}
I already tried to clear data and rebuild the app. Converters for Date in the same class are working. Does the Android TypeConverters not supports Primitive variables?
EDIT:
I register TypeConverter in RoomDatabase class so it is used across whole database.
More specifically about my problem: if I have Query in my Dao class like this:
@Query("SELECT SUM(quantity) FROM production_plan_item")
Double getActivePlanItemsCount();
It may sometimes return value like 2.30000000000001.
I thought that Type converters are used to process returned value of queries. And every time before I save double to database or select double from it, my TypeConverter would round the double for me and I would not have to round it every time I select something.
Otherwise I have to round every single selected double manually.
TypeConvertermethods? What are you expecting them to affect? - CommonsWare