2 Replies - 1263 Views - Last Post: 10 July 2015 - 07:18 PM

#1 plainzwalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-July 15

Help with currency format in textbox

Posted 10 July 2015 - 01:43 AM

Good morning, I am trying to figure out how to format any numbers that are entered into a textbox as currency ($). I have figured out how to convert it after calculations have been done, but I have not been able to figure out how to do it after it is entered initially. Could someone please point me in the right direction please? This has been driving me crazy. I know that you can use String.format ("C") and a couple other methods, but I can't figure out how to put it into my code. I have included my code bellow.

Thank you in advance.

Public Class WebForm1
    Inherits System.Web.UI.Page
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Payment As Double
        Dim LoanIRate As Double
        Dim LoanDuration As Integer
        Dim LoanAmount As Integer

        LoanAmount = Convert.ToInt32(TextBox1.Text)
        LoanIRate = 0.01 * Convert.ToDecimal(TextBox3.Text) / 12
        LoanDuration = Convert.ToInt32(TextBox4.Text)

        Payment = Pmt(LoanIRate, LoanDuration, -LoanAmount, 0)
        TextBox2.Text = Payment.ToString("#.00")
        TextBox2.Enabled = True
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox2.Enabled = False
    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = String.Empty
        TextBox2.Text = String.Empty
        TextBox3.Text = String.Empty
        TextBox4.Text = String.Empty

    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Help with currency format in textbox

#2 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,569
  • Joined: 12-December 12

Re: Help with currency format in textbox

Posted 10 July 2015 - 01:48 AM

Question moved to ASP/ WebForms forum.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Help with currency format in textbox

Posted 10 July 2015 - 07:18 PM

Set your textbox to autopost back and do something like this,

        protected void TextBoxCurrency_TextChanged(object sender, EventArgs e)
        {
            double cur;
            double.TryParse(TextBoxCurrency.Text, out cur);

            TextBoxCurrency.Text = cur.ToString("c");
        }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1