在vb.net中将字符串格式化为Currency时出现问题 [英] Format string to Currency has problem in vb.net

查看:129
本文介绍了在vb.net中将字符串格式化为Currency时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有访客,

我在将字符串格式化为vb.net中的货币时遇到问题.我有一个文本框,它将显示货币.
我使用了文本框的离开事件",当我从文本框离开光标时,货币只显示数字和小数点后两位(12234.00),并且没有货币符号.

以下是我在请假事件中的代码:

Hi all visitors,

I have problem with formatting the string to currency in vb.net. I have a text box and it will show the currency.
I used the Leave Event of text box, when I left cursor from the text box that currency just show the number and 2 decimal places( 12234.00) and there is no currency symbol.

Following is my code in Leave Event:

Private Sub txtprice_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtprice.Leave

        ''12234.00
        Me.txtprice.Text = FormatCurrency(txtprice.Text)

End Sub



但是当我与按钮一起使用时,请单击偶数".货币正常显示($ 123,434,89),即使离开事件的代码相同.

以下是我在Click Event中的代码:



But when I use with button Click Even. The currency shows normally($ 123,434,89), even though code is the same with Leave Event.

Following is my code in Click Event:

Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click

       ''$ 123,434,89
      Me.txtprice.Text = FormatCurrency(txtprice.Text)

 End Sub



请帮帮我.
最好的问候.



Please help me.
Best Regards.

推荐答案

123,434,89),即使代码与Leave Event相同.

以下是我在Click Event中的代码:
123,434,89), even though code is the same with Leave Event.

Following is my code in Click Event:
Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click

       ''


123,434,89 Me.txtprice.Text = FormatCurrency(txtprice.Text) End Sub
123,434,89 Me.txtprice.Text = FormatCurrency(txtprice.Text) End Sub



请帮帮我.
最好的问候.



Please help me.
Best Regards.


FormatCurrency函数在VBScript中使用.它仅在VB.NET中与旧代码向后兼容.您还将传递一个String值,而不是一个格式表编号.

txtprice文本框中的文本转换为数字类型,例如Single,Double或Decimal,然后可以将其传递给String.Format:
The FormatCurrency function is used in VBScript. It''s only in VB.NET for backward compatibility with older code. You''re also passing in a String value, not a formattable number.

Convert the text in your txtprice TextBox to a numeric type, like Single, Double, or Decimal and you can then pass it to String.Format:
Dim price As Single = Single.Parse(txtprice.Text)
txtPrice.Text = String.Format("{0:C}", price)


这只是一个简单的示例,与我在生产质量代码中的实际操作相去甚远.


This is just a quick example and nowhere near what I would actually do in production quality code.


这篇关于在vb.net中将字符串格式化为Currency时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆