0

I'm grabbing the data of the database. If integer I can use getInt, If String I can use getString. But BigDecimal I don't know what to use...

Please Help. Thanks in advance!

while (cursor.moveToNext()) {
    int id = cursor.getInt(0);
    String txnno = cursor.getString(1);
    String name = cursor.getString(2);
    String txndate = cursor.getString(3);
    BigDecimal amount = cursor.getDouble(4);
    String description1 = cursor.getString(5);
    String createddate = cursor.getString(7);

    mList.add(new Model(id, txnno, name, txndate, amount, description1, createddate));
}
T3rrance Low
  • 57
  • 1
  • 10
  • how are you adding it to table ? – Qasim Sep 02 '18 at 05:12
  • I created a row.xml for this. I just want to get Bigdecimal then It done. I would like to know if `Int = getInt` , `String = getString`, then bigDecimal is = to what? @Qasim – T3rrance Low Sep 02 '18 at 05:13

3 Answers3

0

The best optimal choice would be : To get the value using getString() method and then converting it to BigDecimal using suitable constructor.

Refer To: https://developer.android.com/reference/java/math/BigDecimal

Related links: For more :How can I store a BigDecimal (Java) value in a Real (SQlite) column?

Sheetal gupta
  • 191
  • 1
  • 10
0

Generally, the advantage of using big decimal of say double is that you get precision. if you are converting from a double to a big decimal, as suggested by the first answer, you are likely to have those same precision problems double has. It is always better to convert a string to a big decimal.

Ziyaad Shiraz
  • 144
  • 2
  • 7
-1

Use BigDecimal.valueOf(double val):

BigDecimal amount = BigDecimal.valueOf(cursor.getDouble(4));
xingbin
  • 27,410
  • 9
  • 53
  • 103