程序有句代碼是這樣的“Label1.Caption = (Loc(1) * 100 / lDatalen) & "%"運行起來的結果是,程序保留了13位左右的小數點Select Case State'...沒有列舉其它情況。Case icError '11vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfoCase icResponseCompleted ' 12Dim bDone As Boolean: bDone = FalseDim lDatalen As Long: lDatalen = 0vtData() = Inet1.GetChunk(1024, 1) DoEventsOpen savefile.Text For Binary Access Write As #1 If Len(Inet1.GetHeader("Content-Length")) > 0 Then lDatalen = CLng(Inet1.GetHeader("Content-Length"))' CLng(Inet1.GetHeader("Content-Length")) 為文件大小Do While Not bDonePut #1, Loc(1) + 1, vtData()vtData() = Inet1.GetChunk(1024, 1)DoEventsLabel1.Caption = (Loc(1) * 100 / lDatalen) & "%" ProgressBar1.Value = 100 * (Loc(1) / lDatalen)If Loc(1) >= lDatalen Then bDone = TrueLoopClose #1MsgBox "下載完成", vbInformation, End SelectEnd Sub
2 回答

胡說叔叔
TA貢獻1804條經驗 獲得超8個贊
要去掉所有小數是吧
在VB中 /是除法 \是整除 所以只要用
Label1.Caption = (Loc(1) * 100 \ lDatalen) & "%"
就能只保留整數
當然用VB自帶的FORMAT函數也能保留整數
Label1.Caption = Format((Loc(1) * 100 / lDatalen), "0") & "%"
看你這代碼貌似是顯示文件傳輸百分比是吧 FORMAT函數的功能是很強大的 你甚至可以直接讓他顯示百分數 這樣就不用乘100了 如下
Label1.Caption = Format((Loc(1) / lDatalen), "0%")
再給你舉點例子
Format (2, “0.00”)
2.00
Format (.7, “0%”)
70%
Format (1140, “$#,##0”)
$1,140
- 2 回答
- 0 關注
- 199 瀏覽
添加回答
舉報
0/150
提交
取消