[英]How to Save Decimal Without Rounding in VB.NET
I have a program that save amount that is inserted by user我有一个程序可以保存用户插入的金额
here is the function to save the amount inserted by user这里是 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
Then when I insert the amount of 2,32 I expected it to save 2,32 but instead it save 232 instead without the separator然后,当我插入 2,32 的数量时,我希望它能节省 2,32,但它却在没有分隔符的情况下节省了 232
Data type for the amount is decimal(18,2) in database and decimal in vb code class金额的数据类型在数据库中为 decimal(18,2),在 vb 代码中为 decimal class
This is my snippet of class of Amount objNewAmount is这是我的 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
Can anyone help me,谁能帮我,
Snippet for UpdateAmount() 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)
Thank you all @topsail @Hursey and @jmcilhinney for your help I've resorted to using varchar since if I use decimal when ever I use comma it can't be inserted and if I use point it will be gone instead谢谢大家@topsail @Hursey 和@jmcilhinney 的帮助我已经求助于使用 varchar 因为如果我在使用逗号时使用 decimal 则无法插入它,如果我使用 point 它将会消失
So i've decided to change the data type into varchar so it can be inserted to the database and since it doesn't interfere with the calculation所以我决定将数据类型更改为 varchar,这样它就可以插入到数据库中,因为它不会干扰计算
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.