我正在使用Visual Studio 2012和Visual Basic。我的單位轉換器給我一個科學記數法的答案,而不是我正在尋找的實際數字。這發生在釐米到英里的轉換過程中,因爲它的多個地方超過了小數點。我如何格式化輸出以給我實際的數字而不是符號?目前,它給了我這個結果:1釐米= 6.214E-06英里。我想要這個結果:1釐米= 0.000006214英里。在此先感謝,代碼如下。使用Visual Basic的科學記數法問題
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
http://msdn.microsoft.com/en-us/library/txafckwd%28v=vs.110 %29.aspx –
看看這個宏大的圖書館http://www.codeproject.com/Articles/611731/Working-with-Units-and-Amounts – ElektroStudios