Good afternoon, in my project I'm having the following problem.
At the same time there is an activity in which products are added. To add a product, fill in the Name, Quantity and Unit Value fields.
The quantity and unit value fields are multiplied, and the result is added in the TOTAL_PRICE_ITEM
column in my database.
When doing multiplication depending on values, you are returning 3 decimal places
Ex: 1.5 * 1.39 = 2.085 ( 2 integers and 85 thousandths )
Being that I want to return only 2.08 ( 2 integers and 8 cents )
These values are retrieved from the database through the onLoad function that is in the Controller
Controller.class ( loadData )
public Cursor loadData() {
Cursor cursor;
String[] field = {database.ID, database.PRODUCT_NAME, database.COUNT, database.PRICE_UNIT, database.TOTAL_PRICE_ITEM};
db = database.getReadableDatabase();
cursor = db.query(database.TABLE, field, null, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
db.close();
return cursor;
}
And printed in a ListView in my class Main
Controller crud = new Controller(getBaseContext());
final Cursor cursor = crud.loadData();
String[] field = new String[]{CreateDB.ID, CreateDB.PRODUCT_NAME, CreateDB.COUNT, CreateDB.PRICE_UNIT, CreateDB.TOTAL_PRICE_ITEM};
int[] idViews = new int[]{R.id.tvId, R.id.tvProductName, R.id.tvCount, R.id.tvPriceUnit, R.id.tvTotalPriceItem};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(),
R.layout.group_layout, cursor, field, idViews, 0);
list = (ListView) findViewById(R.id.elvProductList);
list.setAdapter(adapter);
The variable String[] field
suppose I'm responsible for saving the values coming from the loadData
function.
The variable int[] idViews
suppose that it is responsible for taking the values stored in the variable String[] field
and putting each one in its respective place.
The value that is coming with 3 decimal places is being displayed in TextView
of id tvTotalPriceItem
.
I want to know how to convert a specific value that is in a set of values.
I do not know if I was very clear about my doubt.
Att.
Giovani Rodrigo