Convert Number to Currancy (Calculation Program)

Fas

Member
Joined
Mar 27, 2006
Messages
15
Programming Experience
Beginner
Hiya i need help please...
i have created a calculator program which canculates 2 numbers
and produces the result
BUTTTT:confused:
the problem i have is that i will like it 2 diplay a currancy(£) not any number
how it looks
Hours Worked (36) NUmber... thats fine
Wage (7.45) number
Wage Result 268.2........... i want this 2 diplay in currancy or something or at least d 0 2 come at d end

it goes on 2 canculate tax and insurance

HERES MY CODEEE

VB.NET:
Public Class Form1
Inherits System.Windows.Forms.Form
 
#Region " Windows Form Designer generated code "
 
Public Sub New()
MyBase.New()
 
'This call is required by the Windows Form Designer.
InitializeComponent()
 
'Add any initialization after the InitializeComponent() call
 
End Sub
 
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
 
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
 
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer. 
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents LbResult As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents LbResult2 As System.Windows.Forms.Label
Friend WithEvents LbTax As System.Windows.Forms.TextBox
Friend WithEvents LbIns As System.Windows.Forms.TextBox
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
Friend WithEvents Print As System.Windows.Forms.Button
Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.LbResult = New System.Windows.Forms.Label
Me.Label9 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Button2 = New System.Windows.Forms.Button
Me.LbResult2 = New System.Windows.Forms.Label
Me.LbTax = New System.Windows.Forms.TextBox
Me.LbIns = New System.Windows.Forms.TextBox
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.Label4 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Label10 = New System.Windows.Forms.Label
Me.CrystalReportViewer1 = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Me.Print = New System.Windows.Forms.Button
Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label1.Location = New System.Drawing.Point(8, 144)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(152, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Staff ID"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label2.Location = New System.Drawing.Point(8, 184)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(152, 24)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Hours Worked"
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label3.Location = New System.Drawing.Point(8, 232)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(152, 24)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Wage Per Hour"
'
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.ForeColor = System.Drawing.Color.Red
Me.TextBox1.Location = New System.Drawing.Point(176, 136)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(112, 26)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Enter"
'
'TextBox2
'
Me.TextBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox2.ForeColor = System.Drawing.Color.Red
Me.TextBox2.Location = New System.Drawing.Point(176, 184)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 26)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = "View Info Bar"
'
'TextBox3
'
Me.TextBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox3.ForeColor = System.Drawing.Color.Red
Me.TextBox3.Location = New System.Drawing.Point(176, 224)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(112, 26)
Me.TextBox3.TabIndex = 5
Me.TextBox3.Text = "View Info Bar"
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.Lime
Me.Button1.Cursor = System.Windows.Forms.Cursors.Hand
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button1.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button1.ForeColor = System.Drawing.SystemColors.InfoText
Me.Button1.Location = New System.Drawing.Point(8, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(144, 40)
Me.Button1.TabIndex = 6
Me.Button1.Text = "Wage"
'
'LbResult
'
Me.LbResult.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.LbResult.ForeColor = System.Drawing.SystemColors.InfoText
Me.LbResult.Location = New System.Drawing.Point(168, 272)
Me.LbResult.Name = "LbResult"
Me.LbResult.Size = New System.Drawing.Size(120, 40)
Me.LbResult.TabIndex = 7
Me.LbResult.Text = "Displays Here"
'
'Label9
'
Me.Label9.Font = New System.Drawing.Font("Times New Roman", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label9.Location = New System.Drawing.Point(8, 328)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(312, 40)
Me.Label9.TabIndex = 8
Me.Label9.Text = "Canculate Gross Pay = (Wage - 20% Tax - 7% Natio" & _
"nal Insurance)"
'
'Label5
'
Me.Label5.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label5.Location = New System.Drawing.Point(8, 96)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(408, 24)
Me.Label5.TabIndex = 9
Me.Label5.Text = "Canculate Wage (Wage Per Hour x Hours Worked)"
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.Lime
Me.Button2.Cursor = System.Windows.Forms.Cursors.Hand
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button2.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button2.ForeColor = System.Drawing.SystemColors.InfoText
Me.Button2.Location = New System.Drawing.Point(8, 464)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(144, 40)
Me.Button2.TabIndex = 10
Me.Button2.Text = "Gross Pay"
'
'LbResult2
'
Me.LbResult2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.LbResult2.ForeColor = System.Drawing.SystemColors.InfoText
Me.LbResult2.Location = New System.Drawing.Point(160, 464)
Me.LbResult2.Name = "LbResult2"
Me.LbResult2.Size = New System.Drawing.Size(128, 40)
Me.LbResult2.TabIndex = 14
Me.LbResult2.Text = "Displays Here"
'
'LbTax
'
Me.LbTax.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.LbTax.ForeColor = System.Drawing.Color.Red
Me.LbTax.Location = New System.Drawing.Point(208, 384)
Me.LbTax.Name = "LbTax"
Me.LbTax.Size = New System.Drawing.Size(56, 26)
Me.LbTax.TabIndex = 16
Me.LbTax.Text = "20%"
'
'LbIns
'
Me.LbIns.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.LbIns.ForeColor = System.Drawing.Color.Red
Me.LbIns.Location = New System.Drawing.Point(208, 416)
Me.LbIns.Name = "LbIns"
Me.LbIns.Size = New System.Drawing.Size(56, 26)
Me.LbIns.TabIndex = 17
Me.LbIns.Text = "7%"
'
'ListBox1
'
Me.ListBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ListBox1.ItemHeight = 20
Me.ListBox1.Items.AddRange(New Object() {"I N F O B A R", "Hours Worked" & Microsoft.VisualBasic.ChrW(9) & "Pay Rate", "36+ Hours" & Microsoft.VisualBasic.ChrW(9) & "£7.45 ", "44 Hours " & Microsoft.VisualBasic.ChrW(9) & Microsoft.VisualBasic.ChrW(9) & "£10.32", "45+ Hours" & Microsoft.VisualBasic.ChrW(9) & "£15.66 "})
Me.ListBox1.Location = New System.Drawing.Point(328, 128)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(224, 104)
Me.ListBox1.TabIndex = 18
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label4.Location = New System.Drawing.Point(8, 384)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(192, 24)
Me.Label4.TabIndex = 19
Me.Label4.Text = "Tax Deduction"
'
'Label6
'
Me.Label6.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label6.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label6.Location = New System.Drawing.Point(8, 424)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(192, 24)
Me.Label6.TabIndex = 20
Me.Label6.Text = "Insurance Deduction"
'
'Label7
'
Me.Label7.Font = New System.Drawing.Font("Times New Roman", 20.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label7.Location = New System.Drawing.Point(16, 16)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(320, 40)
Me.Label7.TabIndex = 21
Me.Label7.Text = "BestWay Pay Calculator"
Me.Label7.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'Label8
'
Me.Label8.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label8.ForeColor = System.Drawing.Color.Red
Me.Label8.Location = New System.Drawing.Point(336, 24)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(248, 24)
Me.Label8.TabIndex = 22
Me.Label8.Text = "Copyrights Fa$ Software Ltd"
'
'PictureBox1
'
Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
Me.PictureBox1.Location = New System.Drawing.Point(312, 240)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(264, 304)
Me.PictureBox1.TabIndex = 23
Me.PictureBox1.TabStop = False
'
'Label10
'
Me.Label10.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label10.ForeColor = System.Drawing.Color.Red
Me.Label10.Location = New System.Drawing.Point(16, 56)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(136, 16)
Me.Label10.TabIndex = 24
Me.Label10.Text = "Version 1.0"
'
'CrystalReportViewer1
'
Me.CrystalReportViewer1.ActiveViewIndex = -1
Me.CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
Me.CrystalReportViewer1.ReportSource = Nothing
Me.CrystalReportViewer1.TabIndex = 0
'
'Print
'
Me.Print.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Print.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Print.Location = New System.Drawing.Point(16, 520)
Me.Print.Name = "Print"
Me.Print.Size = New System.Drawing.Size(136, 32)
Me.Print.TabIndex = 25
Me.Print.Text = "Print"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.ClientSize = New System.Drawing.Size(608, 558)
Me.Controls.Add(Me.Print)
Me.Controls.Add(Me.Label10)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.LbIns)
Me.Controls.Add(Me.LbTax)
Me.Controls.Add(Me.LbResult2)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.LbResult)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Cursor = System.Windows.Forms.Cursors.Arrow
Me.Name = "Form1"
Me.Text = "BestWay Pay Calculator"
Me.ResumeLayout(False)
 
End Sub
 
#End Region
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LbResult.Text = Str(Val(TextBox2.Text) * Val(TextBox3.Text))
End Sub
 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
LbResult.Text = Str(Val(TextBox2.Text) * Val(TextBox3.Text))
LbResult2.Text = Str(Val(LbResult.Text) - Val(LbTax.Text) - Val(LbIns.Text))
End Sub
 
End Class
 
Last edited by a moderator:
Hi Fas,
Wellcome to the forum :)
Well, if you want to display it as a currency you suppose to Format given result. Notice that Val is parsing text converting it in value with double precision datatype. Anyway, you can format the string as it follows:
VB.NET:
Dim result as Double = Val(TextBox2.Text) * Val(TextBox3.Text)
LbResult.Text = String.Format("{0:n2}", result)

HTH
Regards ;)
 
THANX MATE BUTTT
loool i did it n its great but how to i do a similar thing 4 d deduction canculation its displaying silly i try 2 copy paste what u told me for d irst 1 but its build error result allready used or something ????? what do i do now mate thanx 4 ue help this last thing u could save me life


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
LbResult.Text = String.Format("{0:n2}", result)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
LbResult.Text = String.Format("{0:n2}", result)
Dim result As Double = Val(LbResult.Text) - Val(LbTax.Text) - Val(LbIns.Text)
LbResult2.Text = String.Format("{0:n2}", result)
End Sub
End Class
 
just declare another var for the 2nd result or simply use the existing 'result' variable i.e.
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
LbResult.Text = String.Format("{0:n2}", result)
Dim [B]result2[/B] As Double = Val(LbResult.Text) - Val(LbTax.Text) - Val(LbIns.Text)
LbResult2.Text = String.Format("{0:n2}", [B]result2[/B])
End Sub

or

VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
LbResult.Text = String.Format("{0:n2}", result)
[B]result[/B] = Val(LbResult.Text) - Val(LbTax.Text) - Val(LbIns.Text)
LbResult2.Text = String.Format("{0:n2}", [B]result[/B])
End Sub

You cannot declare two variable with a same name inside one procedure

HTH
Regards ;)

p.s. please use [ code ][ /code ] tags when you are including code in your post
 
Back
Top