查看完整版本: 浮點數儲存至資料庫變整數
頁: [1]

terrypen 發表於 2014-9-23 09:12 PM

浮點數儲存至資料庫變整數

上次經過各位先進的解說~~我對數值的運算稍微有了瞭解~~只是~在datagridview上做運算都正常,儲存至資料庫後數值卻變整數~~資料庫的資料型態是decimal vb.net dataset也是decimal,怎會儲存至MySQL資料庫卻變成整數~~暈~~@@
再麻煩先進們幫小弟解惑一下~~謝謝

<div></div>

Jeepluo 發表於 2014-9-24 08:27 PM

要看你的程式是怎麼寫的,主要是你在做運算時,變數是符點型的嗎?如果都沒有錯,還是一樣, 你可以試著在 前面加入 1.0 * 你的值,強迫轉換。

terrypen 發表於 2014-9-24 09:32 PM

請教一下Jeepluo~~我變數iQuantity 是有小數點,但是UnitPrice 是整數~~我全部都宣告成decimail 能相乘嗎?是不是UnitPrice 是要強迫轉換成有小數點的數值才行~~ Dim iQuantity As Decimal
        Dim iAmount As Decimal
        Dim iUnitPrice As Decimal

        iQuantity = GipquantitydetailsDataGridView.Rows(e.RowIndex).Cells("dgvQuantity").Value

        iUnitPrice = GipquantitydetailsDataGridView.Rows(e.RowIndex).Cells("dgvUnitPrice").Value

        iAmount = iQuantity * iUnitPrice
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div>

terrypen 發表於 2014-9-25 09:30 PM

謝謝Jeepluo您的幫忙~~問題已經解決了~~我是資料庫少設小數點位數~~第一次使用MySQL
真不好意思~~謝謝
頁: [1]