title: How can I store a BigDecimal (Java) value in a Real (SQlite) column?
body: <p>I'm still having big problems with BigDecimal (the trail of tears started <a href="https://stackoverflow.com/questions/23017583/is-javas-bigdecimal-the-closest-data-type-corresponding-to-cs-decimal">here</a>, and continued to <a href="https://stackoverflow.com/questions/23021176/how-can-i-write-sqlite-real-vals-to-java-bigdecimal-values">here</a> so far.</p>
  <p>Now I've got the opposite problem - going from BigDecimal in the POJO to REAL in the SQLite table.</p>
  <p>The POJO is defined as:</p>
  <pre><code>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;
      }
      . . .
  </code></pre>
  <p>This code, attempting to get the data in shape to be able to posted to the SQLite table (where the corresponding columns are data type REAL, SQLite's only real/float data type):</p>
  <pre><code>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;
  }
  </code></pre>
  <p>For the COLUMN_COST line above (the &quot;MARGIN&quot; and &quot;LISTPRICE&quot; columns have the same problem), I get, &quot;<em>error: incompatible types: BigDecimal cannot be converted to Double</em>&quot; when I try this:</p>
  <pre><code>values.put(COLUMN_COST, (Double) delItem.get_cost());
  </code></pre>
  <p>...and for the commented out code (both lines), namely this:</p>
  <pre><code>values.put(COLUMN_COST, delItem.get_cost());
  </code></pre>
  <p>...and this:</p>
  <pre><code>values.put(COLUMN_COST, new BigDecimal(delItem.get_cost()));
  </code></pre>
  <p>...I get:</p>
  <pre><code>error: no suitable method found for put(String,BigDecimal)
  method ContentValues.put(String,String) is not applicable
  (argument mismatch; BigDecimal cannot be converted to String)
  method ContentValues.put(String,Byte) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Byte)
  method ContentValues.put(String,Short) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Short)
  method ContentValues.put(String,Integer) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Integer)
  method ContentValues.put(String,Long) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Long)
  method ContentValues.put(String,Float) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Float)
  method ContentValues.put(String,Double) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Double)
  method ContentValues.put(String,Boolean) is not applicable
  (argument mismatch; BigDecimal cannot be converted to Boolean)
  method ContentValues.put(String,byte[]) is not applicable
  (argument mismatch; BigDecimal cannot be converted to byte[])
  </code></pre>
  <p>So how can I manipulate the BigDecimal value in the so that it will be accepted by the ContentValues instance?</p>
  <h2 id="update">UPDATE</h2>
  <p>I may have to temporarily fudge it by just ignoring those vals and changing the DDL to:</p>
  <pre><code>//+ COLUMN_COST + &quot; REAL,&quot;  + COLUMN_MARGIN + &quot; REAL,&quot; + COLUMN_LISTPRICE + &quot; REAL,&quot;
  + COLUMN_COST + &quot; REAL DEFAULT 0,&quot;  + COLUMN_MARGIN + &quot; REAL DEFAULT 0,&quot; + COLUMN_LISTPRICE + &quot; REAL DEFAULT 0,&quot;
  </code></pre>