以下代码是excel userfrom并从文本框中获取数字数据并计算公式对应的组合框。但是当combobox.text =" b"对于示例2的文本框的某些值,结果为7.46426393229446E-02,但必须为0.074662
dim a as single
a= val(textbox1)
If ComboBox1.Text = "A" Then
j = 0.05 * (a) ^ 0.9
ElseIf ComboBox1.Text = "B" Then
j = 0.04 * (a) ^ 0.9
ElseIf ComboBox1.Text = "C" Then
j = 0.064 * (a) ^ 0.75
ElseIf ComboBox1.Text = "D" Or ComboBox6.Text = "E" Then
j = 0.08 * (a) ^ 0.75
Else
j = 0.05 * (a) ^ 0.75
End If
label1的= j的
答案 0 :(得分:1)
而不是
0.04 * (a) ^ 0.9
使用
0.04 * CDec((a) ^ 0.9)
或CDec(0.04 * (a) ^ 0.9)
这应该可以解决您的问题。所以你的代码将是
Dim a As Single
a = Val(textbox1)
If ComboBox1.Text = "A" Then
j = 0.05 * CDec((a) ^ 0.9)
ElseIf ComboBox1.Text = "B" Then
j = 0.04 * CDec((a) ^ 0.9)
ElseIf ComboBox1.Text = "C" Then
j = 0.064 * ((a) ^ 0.75)
ElseIf ComboBox1.Text = "D" Or ComboBox6.Text = "E" Then
j = 0.08 * CDec((a) ^ 0.75)
Else
j = 0.05 * CDec((a) ^ 0.75)
End If
CDec
函数将值转换为十进制。