[英]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.