Hi guys i am trying to do this
ContentValues initialValues = new ContentValues();
initialValues.put("monthlyBudget",account.monthlyBudge
where MonthlyBudget is BigDecimal variable.
Now it gives an error that change the type of monthlyBudget to String.
How can i resolve this issue.
The
ContentValuesdocumentation lists all the overloads ofput– and none of them takes aBigDecimal, so I’m not surprised it’s failing.Two options you could take:
If this is a currency value (which it sounds like) you may be able to deal with it to a fixed precision, e.g. 2 decimal places, and with relatively limited range. Just multiply your
BigDecimalby 100, take the integer result as alongand then put thelonginto yourContentValues. When you extract it later, create aBigDecimalfrom thelongand divide it by 100. (Or change all your code to treat the budget as an integer number of cents everywhere, potentially.)You could store the string representation, and pass that string to the
BigDecimalconstructor when you fetch it.