本文介绍了在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.

推荐答案

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

       ''




请帮帮我.
最好的问候.



Please help me.
Best Regards.


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时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:05