android - How can I store a BigDecimal (Java) value in a Real (SQlite) column? -


i'm still having big problems bigdecimal (the trail of tears started here, , continued here far.

now i've got opposite problem - going bigdecimal in pojo real in sqlite table.

the pojo defined as:

public class deliveryitem {     private int _id;     private string _invoicenumber;     private string _upc_plu;     private string _vendoritemid;     private int _packsize;     private string _description;     private bigdecimal _cost;     private bigdecimal _margin;     private bigdecimal _listprice;     private int _departmentnumber;     private string _subdepartment;     private string _quantity;      public void setid(int id) {         this._id = id;     }     . . . 

this code, attempting data in shape able posted sqlite table (where corresponding columns data type real, sqlite's real/float data type):

public long adddeliveryitem(deliveryitem delitem) {     long idadded = 0;     contentvalues values = new contentvalues();     values.put(column_invoicenum, delitem.get_invoicenumber());     values.put(column_upcplu, delitem.get_upc_plu());     values.put(column_vendoritemid, delitem.get_vendoritemid());     values.put(column_packsize, delitem.get_packsize());     values.put(column_description, delitem.get_description());     //values.put(column_cost, delitem.get_cost());     //values.put(column_cost, new bigdecimal(delitem.get_cost()));     values.put(column_cost, (double) delitem.get_cost());     values.put(column_margin, delitem.get_margin());     values.put(column_listprice, delitem.get_listprice());     values.put(column_deptnum, delitem.get_departmentnumber());     values.put(column_subdept, delitem.get_subdepartment());     values.put(column_qty, delitem.get_quantity());      sqlitedatabase db = this.getwritabledatabase();      if (db != null) {         idadded = db.insert(table_deliveryitems, null, values);     }     if (db != null) {         db.close();     }     return idadded; } 

for column_cost line above (the "margin" , "listprice" columns have same problem), get, "error: incompatible types: bigdecimal cannot converted double" when try this:

values.put(column_cost, (double) delitem.get_cost()); 

...and commented out code (both lines), namely this:

values.put(column_cost, delitem.get_cost()); 

...and this:

values.put(column_cost, new bigdecimal(delitem.get_cost())); 

...i get, "error: no suitable method found put(string,bigdecimal) method contentvalues.put(string,string) not applicable (argument mismatch; bigdecimal cannot converted string) method contentvalues.put(string,byte) not applicable (argument mismatch; bigdecimal cannot converted byte) method contentvalues.put(string,short) not applicable (argument mismatch; bigdecimal cannot converted short) method contentvalues.put(string,integer) not applicable (argument mismatch; bigdecimal cannot converted integer) method contentvalues.put(string,long) not applicable (argument mismatch; bigdecimal cannot converted long) method contentvalues.put(string,float) not applicable (argument mismatch; bigdecimal cannot converted float) method contentvalues.put(string,double) not applicable (argument mismatch; bigdecimal cannot converted double) method contentvalues.put(string,boolean) not applicable (argument mismatch; bigdecimal cannot converted boolean) method contentvalues.put(string,byte[]) not applicable (argument mismatch; bigdecimal cannot converted byte[])"

so how can manipulate bigdecimal value in accepted contentvalues instance?

update

i may have temporarily fudge ignoring vals , changing ddl to:

//+ column_cost + " real,"  + column_margin + " real," + column_listprice + " real," + column_cost + " real default 0,"  + column_margin + " real default 0," + column_listprice + " real default 0," 

so how can manipulate bigdecimal value in accepted contentvalues instance?

well, can call doublevalue() on bigdecimal downgrade double, can go in contentvalues (after autoboxing double). or, can store string representation in text column. or, can store unscaledvalue() , scale() in 2 integer columns.

but sqlite's closest match real

no, not.

you seem interested in storing pricing data in sqlite. search storing prices in sqlite on major search engine turns up:

the consensus store value integer column, priced in smallest individual currency unit (e.g., cents currency values in dollars), or else appropriate (e.g., tenths of cent if that's finest granularity of prices).

your pojo hold int values match.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -