开发者

VS2010 : Format a text box for currency

开发者 https://www.devze.com 2023-03-19 05:06 出处:网络
I have check boxes selecting prices tha开发者_开发技巧t go straight to the text box, how can I make it so it will display $ and two decimal places?

I have check boxes selecting prices tha开发者_开发技巧t go straight to the text box, how can I make it so it will display $ and two decimal places?

Code:

Dim total As Double
    If rb_s1.Checked = True Then
        txt_1.Text = "650.00"
    Else
        txt_1.Text = ""
        txt_1.Text = total


use the formatcurrency() method.

  txt_1.text = formatcurrency(650.0)

EDIT: Please remember to use YOUR variable names and to not copy and paste sample code. This format will work with your code when placed into your if statement.


Numeric Datatypes have a ToString method you can call. ToString() will just convert the numeric value to a string, but you can optionally specify a format, by putting the format in as the method parameter.

I don't know all the formats, but I do know "C2" is currency with 2 decimal places. For example, in your posted code:

Dim total As Double
    If rb_s1.Checked = True Then
        txt_1.Text = "650.00"
    Else
        txt_1.Text = String.Empty 'String.Empty is just a more precise way than ""
        txt_1.Text = total.ToString("C2")


I found solution how to convert to Currency I ok

*

  1. dim test as string
  2. test="1000"
  3. txtBalance.Text = CDbl(result).ToString("#,##0.00")

*


I found solution how to convert to Currency. Try this :

Textbox1.Text = String.Format("{0:n2} $", CType(Textbox1.Text, Double))


Use the Format function:

txt_1.text = Format("YOUR VALUE","#,##0.00")

The first param is your data. The second param indicates how you want that data formatted.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号