Brain fart

  • Thread starter Thread starter Mike & Dyan
  • Start date Start date
M

Mike & Dyan

I am making a Mileage Calculator for work to keep track of mileage on my
car. I think I am missing something. In the answer box I only want 2
decimal places to right to show. For some reason I get it to work. Here is
my code.

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click

Dim decMilesDriven As Decimal

Dim decgallonsofGas As Decimal

Dim decMPG As Decimal

decMilesDriven = Val(tbMilesDriven.Text)

decgallonsofGas = Val(tbGallonsofGas.Text)

decMPG = decMilesDriven / decgallonsofGas

lblMPGResults.Text = String.Format("{0:F}", decMPG & " MPG")

End Sub
 
Hi Mike & Dyan

Not using String.Format you can do

lblMPGResults.Text = decMPG.ToString("F2") & " MPG"
 
Back
Top