[英]How to write in vb.net a decimal number without rounding the 12 digits after the decimal point?
[英]How to Save Decimal Without Rounding in VB.NET
我有一個程序可以保存用戶插入的金額
這里是 function 來保存用戶輸入的金額
Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Submit.Click
If Not Page.IsValid Then
Exit Sub
End If
Dim objNewAmount As New Amount
If Not objCurrAmount Is Nothing Then
objNewAmount.AmountID = objCurrAmount.AmountID
isUpdate = True
End If
objNewAmount.AmountName = txtAmountName.Text
Dim amount As Double = txtAmount.Text
objNewAmount.Amount= amount
Dim IsError As Boolean = False
Try
objNewAmount.AmountName.UpdateAmount()
Catch ex As Exception
lblInfo.Text = ex.Message
IsError = True
End Try
If Not IsError Then
Response.Redirect("AmountList.aspx", True)
End If
End Sub
然后,當我插入 2,32 的數量時,我希望它能節省 2,32,但它卻在沒有分隔符的情況下節省了 232
金額的數據類型在數據庫中為 decimal(18,2),在 vb 代碼中為 decimal class
這是我的 class 的 Amount objNewAmount 片段是
Private _Tarif As Decimal = 0
Public Property Tarif() As Decimal
Get
Return _Tarif
End Get
Set(ByVal value As Decimal)
_Tarif = value
End Set
End Property
誰能幫我,
UpdateAmount() 的片段
strSQL.Append(" begin" & vbCrLf)
strSQL.Append(" " & GetNewShortIDQuery("m_Amount", "AmountID", "JH", "@NewID", 6, 4) & vbCrLf)
strSQL.Append(" insert into m_Amount" & vbCrLf)
strSQL.Append(" select @NewID" & vbCrLf)
strSQL.Append(" , " & ReplaceQuota(AmountName) & vbCrLf)
strSQL.Append(" , " & ReplaceQuota(Amount, "num") & vbCrLf)
strSQL.Append(" , " & ReplaceQuota(CreatorID) & vbCrLf)
strSQL.Append(" , " & ReplaceQuota(CreatorIP) & vbCrLf)
strSQL.Append(" , " & ReplaceQuota(CreatorDateTime, "datetime") & vbCrLf)
strSQL.Append(" , null" & vbCrLf)
strSQL.Append(" , null" & vbCrLf)
strSQL.Append(" , null;" & vbCrLf)
strSQL.Append(" end" & vbCrLf)
謝謝大家@topsail @Hursey 和@jmcilhinney 的幫助我已經求助於使用 varchar 因為如果我在使用逗號時使用 decimal 則無法插入它,如果我使用 point 它將會消失
所以我決定將數據類型更改為 varchar,這樣它就可以插入到數據庫中,因為它不會干擾計算
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.