jonny
jonny

Reputation: 11

VS2010 : Format a text box for currency

I have check boxes selecting prices that 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

Upvotes: 1

Views: 48752

Answers (5)

asdfg 123dss
asdfg 123dss

Reputation: 1

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.

Upvotes: 0

Mohamed Ibrahim
Mohamed Ibrahim

Reputation: 13

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

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

Upvotes: 0

SOPHORS MEN
SOPHORS MEN

Reputation: 1

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")

*

Upvotes: 0

4o66
4o66

Reputation: 1

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")

Upvotes: 0

MGZero
MGZero

Reputation: 5963

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.

Upvotes: 4

Related Questions