PCDVD數位科技討論區
PCDVD數位科技討論區   註冊 常見問題 標記討論區為已讀

回到   PCDVD數位科技討論區 > 其他群組 > 疑難雜症區
帳戶
密碼
 

回應
 
主題工具
Midgard
Advance Member
 

加入日期: Jun 2002
您的住址: Taipei, Taiwan
文章: 497
Microsoft Visual Basic 6.0 加法問題

請問各位
一個很簡單的 VB加法,程式碼如下

Dim temp As Single

Private Sub Command1_Click()

Label1.Caption = temp
temp = temp + 0.1

End Sub


選擇在Label1裡觀看加法情形,發現有趣的情況
Command1每按一次,Label1秀出結果
依序如下

0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8000001
0.9000001
1
1.1
1.2

有人可以解釋那0.000001的來歷嗎 ?
希望有高手解答 ~
     
      
舊 2006-10-20, 06:10 PM #1
回應時引用此文章
Midgard離線中  
kec
Major Member
 
kec的大頭照
 

加入日期: Feb 2004
您的住址: Terran Empire
文章: 283
因為浮點數無法精確地儲存某些數值。

http://en.wikipedia.org/wiki/Floating-point_number
引用:
Floating-point numbers are intended to approximate the mathematical real numbers. But while the real numbers form a continuum that can be subdivided without limit, floating-point numbers have only finite resolution—they can only represent discrete points on the real number line. (In double precision representation, consecutive points differ by about 1 part in 1016.) That is, they can only represent a subset of the reals.
 
舊 2006-10-21, 06:00 AM #2
回應時引用此文章
kec離線中  
Midgard
Advance Member
 

加入日期: Jun 2002
您的住址: Taipei, Taiwan
文章: 497
引用:
作者kec
因為浮點數無法精確地儲存某些數值。

http://en.wikipedia.org/wiki/Floating-point_number


嗯 ~ 大約了解你的意思了 感謝 ~
舊 2006-10-21, 11:29 AM #3
回應時引用此文章
Midgard離線中  


回應


POPIN
主題工具

發表文章規則
不可以發起新主題
不可以回應主題
不可以上傳附加檔案
不可以編輯您的文章

vB 代碼打開
[IMG]代碼打開
HTML代碼關閉



所有的時間均為GMT +8。 現在的時間是10:30 AM.


vBulletin Version 3.0.1
powered_by_vbulletin 2025。