vb:去掉小数点,其他数不变.(类似于有效数字,但不要小数点)
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/08 03:47:09
vb:去掉小数点,其他数不变.(类似于有效数字,但不要小数点)
例如:0.002354变成2345,07734.03503变成773403503.
例如:0.002354变成2345,07734.03503变成773403503.
Private Sub Command1_Click()
Dim m As String,s As String,l As Integer,i As Integer,t As String
s = Text1.Text
l = Len(s)
For i = 1 To l
t = Mid(s,i,1)
If n = 1 Then
If t "." Then
m = m & t
End If
Else
If t "0" And t "." Then
n = 1
m = m & t
End If
End If
Next i
Text2.Text = m
End Sub
再问: O(∩_∩)O谢谢!可以了。不过n是什么?要声明吗?
再答: 你可以dim n as interger 比如0.0908,当i=3时,执行else下面的代码,即n=1,并去除0和小数点,保留数字9,然后因为n=1就只能执行else上面的代码,即数字9以后的0保留,没有n的话,0.0908就变成98而不是908了。
Dim m As String,s As String,l As Integer,i As Integer,t As String
s = Text1.Text
l = Len(s)
For i = 1 To l
t = Mid(s,i,1)
If n = 1 Then
If t "." Then
m = m & t
End If
Else
If t "0" And t "." Then
n = 1
m = m & t
End If
End If
Next i
Text2.Text = m
End Sub
再问: O(∩_∩)O谢谢!可以了。不过n是什么?要声明吗?
再答: 你可以dim n as interger 比如0.0908,当i=3时,执行else下面的代码,即n=1,并去除0和小数点,保留数字9,然后因为n=1就只能执行else上面的代码,即数字9以后的0保留,没有n的话,0.0908就变成98而不是908了。