As you can see, I am extremely young on this forum; I joined about 5 minutes ago lol. I've been in vb.net since August when I started college. I came into this with no experience in computer programming but was fascinated with how this stuff works.
I decided to make a few basic forms outside of class to practice a bit, and one I am doing now is a simple temperature conversion form. The user types in a temperature in Fahrenheit and presses convert, then it converts the temperature to Celsius and Kelvin. Everything works, but I am trying to have the Celsius/Kelvin round off to two decimal places.
Here is what I have so far:
Public Class Form1
Dim dblFahrenheit As Double
Dim dblCelsius As Double
Dim dblKelvin As Double
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
dblFahrenheit = CDbl(txtFahrenheit.Text)
dblCelsius = 5 * (dblFahrenheit - 32) / 9
lblCelsius.Text = dblCelsius.ToString
dblKelvin = 5 * (dblFahrenheit - 32) / 9 + 273.15
lblKelvin.Text = dblKelvin.ToString
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFahrenheit.Clear()
lblCelsius.Text = String.Empty
lblKelvin.Text = String.Empty
txtFahrenheit.Focus()
End Sub
End Class
I have searched for a while now, but can't seem to find an answer. I end up getting confused lol.
If anyone could help me out with this, I'd appreciate it very much!
I decided to make a few basic forms outside of class to practice a bit, and one I am doing now is a simple temperature conversion form. The user types in a temperature in Fahrenheit and presses convert, then it converts the temperature to Celsius and Kelvin. Everything works, but I am trying to have the Celsius/Kelvin round off to two decimal places.
Here is what I have so far:
Public Class Form1
Dim dblFahrenheit As Double
Dim dblCelsius As Double
Dim dblKelvin As Double
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
dblFahrenheit = CDbl(txtFahrenheit.Text)
dblCelsius = 5 * (dblFahrenheit - 32) / 9
lblCelsius.Text = dblCelsius.ToString
dblKelvin = 5 * (dblFahrenheit - 32) / 9 + 273.15
lblKelvin.Text = dblKelvin.ToString
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFahrenheit.Clear()
lblCelsius.Text = String.Empty
lblKelvin.Text = String.Empty
txtFahrenheit.Focus()
End Sub
End Class
I have searched for a while now, but can't seem to find an answer. I end up getting confused lol.
If anyone could help me out with this, I'd appreciate it very much!