将VB文本框内输入的数字转为货币形式

来源:百度知道 编辑:UC知道 时间:2024/06/01 21:58:28
如输入12000 则自动在文本框内显示 12,000.00 在线等
可以加分(⊙o⊙)哦

Text1.Text = Format(Val(Text1.Text), "#,##0.00")

用数字格式函数format(12000,"#,##0.00")就可以了

Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave
Dim str As String = TextBox1.Text.Trim()
If Not String.IsNullOrEmpty(str) And IsNumeric(str) Then
TextBox1.Text = FormatCurrency(str)
End If
End Sub