title: Calculated amount in Interface aren't not saved into SQLlite DB, only different amount is being saved
body: <p>I'm having problem with the calculations. When build the system and test it, the correct amount showed in the interface isn't showing up/saved in database. The amount is something different than the one in the interface.</p>
  
  <p>Note: </p>
  
  <ol>
  <li>SELECT SUM(TotalPrice) FROM Sold (Screenshot of the Sold table will be attached together. </li>
  <li>I will attach the screenshots below. Have a look on it to get clear picture of the situation.</li>
  <li>I've marked the problem code with the comment <strong>//&lt;--THIS-->//</strong>.</li>
  </ol>
  
  <p>Here's my code:</p>
  
  <pre><code>void CashRegister::on_pushButton_next_clicked()
  {
      ui-&gt;tableView-&gt;show();
      ui-&gt;pushButton_finish-&gt;show();
      ui-&gt;label_totalAmount-&gt;show();
  
      QString receiptNo = ui-&gt;label_receiptNum-&gt;text();
      QString itemSelect = ui-&gt;comboBox_itemID-&gt;currentText();
      QString qtySold = ui-&gt;lineEdit_qtySold-&gt;text();
      QDate currentDate = QDate::currentDate();   //&lt;--Solved--&gt;//
      //QString totalPrice1 = ui-&gt;label_totalAmount-&gt;text();
  
      double price=0, totalPrice=0;
  
      QSqlQuery myqry;
      myqry.exec("SELECT ItemPrice, ItemName FROM Item WHERE ItemId='"+itemSelect+"' ");
      if (myqry.next())
          price = myqry.value(0).toDouble();
  
      totalPrice = price * qtySold.toInt();
  
      QString totalPriceString = QString::number(totalPrice);
  
      myqry.prepare("INSERT INTO Sold (ReceiptId, ItemId, SoldQuantity, TotalPrice) VALUES ('"+receiptNo+"', '"+itemSelect+"', '"+qtySold+"', '"+totalPriceString+"') ");
      myqry.exec();
  
      ui-&gt;comboBox_itemID-&gt;setCurrentIndex(0);
      ui-&gt;lineEdit_qtySold-&gt;clear();
  
      myqry.prepare("SELECT Item.ItemId, Item.ItemName, Item.ItemPrice, Sold.SoldQuantity FROM Item, Sold WHERE Item.ItemId = Sold.ItemId AND Sold.ReceiptId='"+receiptNo+"' ");
      myqry.exec();
  
  
      QSqlQueryModel *myModel = new QSqlQueryModel();
      myModel-&gt;setQuery(myqry);
      ui-&gt;tableView-&gt;setModel(myModel);
  
      double sum = 0;
  
      myqry.exec("SELECT SUM(TotalPrice) FROM Sold WHERE ReceiptId = '"+receiptNo+"' ");
      if (myqry.next())
          sum += myqry.value(0).toDouble();
  
      ui-&gt;label_totalAmount-&gt;setText("TOTAL AMOUNT: RM" + QString::number(sum));
  
      QString totalPriceReceipt = QString::number(sum);
  
      //&lt;--THIS--&gt;//
      myqry.prepare("INSERT INTO Receipt (ReceiptId, ReceiptDate, ReceiptAmount) VALUES ('"+receiptNo+"', '"+currentDate.toString()+"', '"+totalPriceReceipt+"') ");
      myqry.exec();
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aZCxJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aZCxJ.jpg" alt="Different amount in Interface and DB"></a></p>
  
  <p><a href="https://i.stack.imgur.com/rdVcC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rdVcC.jpg" alt="Sold Table"></a></p>