I am using Visual Studio 2012 and Visual Basic. My unit converter gives me an answer in scientific notation instead of the actual number that I am looking for. This occurs during the centimeter to mile conversion due to its multiple places past the decimal point. How can I format the output to give me the actual number instead of the notation? Currently, it is giving me this result: 1 centimeter = 6.214E-06 mile. I want this result: 1 centimeter = 0.000006214 mile. Thanks in advance, code is below.
Private Function GetLength1(ByVal dblLengthUnit1 As Double) As Double
Dim dblResult1 As Double
If cboUnitType.SelectedItem = "Length" Then
' converts centimeter to...
If cbo1.SelectedItem = "Centimeter" Then
If cbo2.SelectedItem = "Kilometer" Then
dblResult1 = (dblLengthUnit1 * 0.0001)
ElseIf cbo2.SelectedItem = "Meter" Then
dblResult1 = (dblLengthUnit1 * 0.01)
ElseIf cbo2.SelectedItem = "Centimeter" Then
dblResult1 = txtUnit1.Text
ElseIf cbo2.SelectedItem = "Millimeter" Then
dblResult1 = (dblLengthUnit1 * 10)
ElseIf cbo2.SelectedItem = "Mile" Then
dblResult1 = (dblLengthUnit1 * 0.000006214)
ElseIf cbo2.SelectedItem = "Yard" Then
dblResult1 = (dblLengthUnit1 * 0.010936133)
ElseIf cbo2.SelectedItem = "Foot" Then
dblResult1 = (dblLengthUnit1 * 0.032808399)
ElseIf cbo2.SelectedItem = "Inch" Then
dblResult1 = (dblLengthUnit1 * 0.393700787)
End If
End If
Return dblResult1.ToString.Trim
End Function
Private Sub txtUnit1_TextChanged(sender As Object, e As EventArgs) Handles txtUnit1.TextChanged
If suppressTextBox1TextChanged = False Then
Double.TryParse(txtUnit1.Text, dblUnit1)
' if String.Empty
If txtUnit1.Text = "" Then
txtUnit2.Text = ""
Else
' trigger the function
suppressTextBox2TextChanged = True
txtUnit2.Text = GetLength1(dblUnit1)
suppressTextBox2TextChanged = False
End If
End If
End Sub