Reputation: 9101
I am storing a value in database as 0.0004
and displaying the same in EditText
but in edittext it as showing as 4.0E-4
tried a lot of things nothing seems to work for me.
Storing value in database is fine but when coming to edittext display it is wrong.
What I have tried:
Followed below process
DecimalFormat FORMATTER = new DecimalFormat("0.####");
textvalue.setText(REAL_FORMATTER.format(new_percent.getLong(new_percent.getColumnIndex(bt.column2))));
but the result is same no chage.
Can any one help to solve this..I want the display in edit text as 0.0004
not as 4.0E-4
Thanks for your time.
Upvotes: 0
Views: 466
Reputation: 9101
Finally achieved as below.
BigDecimal.valueOf(Cursor.getDouble(Cursor.getColumnIndex(bt.column2)))
Upvotes: 0
Reputation: 642
Why you retrieve 0.0004 value with the getLong mehod?
As I suppose, you store the 0.0004 in a database in a REAL column type, so you should retrieve this with getDouble.
DecimalFormat formatter = new DecimalFormat("0.####");
textValue.setText(
formatter.format(
new_percent.getDouble(
new_percent.getColumnIndexOrThrow(bt.column2))));
Upvotes: 0
Reputation: 26198
Instead of giving pattern to the BigDecimal
just send directly the value to the constructor parameter.
example:
BigDecimal number = new BigDecimal("4.0E-4");
int ints= number.intValue(); //BigDecimal to integer
double doubles= number.doubleValue(); //BigDecimal to double
Upvotes: 1