[.NET] 奇怪的數值問題

看板Visual_Basic作者 (阿章)時間18年前 (2007/08/13 21:53), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串1/1
Public Sub caraction(ByVal steps As Integer, ByVal character As String) Dim temp5, temp4, temp3, temp2, temp1, a, b, c, d, e As Integer temp5 = steps / 10000 a = steps Mod 10000 temp4 = a / 1000 b = a Mod 1000 temp3 = b / 100 c = b Mod 100 temp2 = c / 10 temp1 = c Mod 10 假如我的steps是64的話 會得到temp5=0 temp4=0 temp3=1 temp2=6 temp1=4 位什麼會出現這麼奇怪的結果? 煩請大家幫忙一下摟,謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.121.135.238

08/13 22:03, , 1F
temp3=(0.64).ToInt32()
08/13 22:03, 1F

08/13 22:04, , 2F
08/13 22:04, 2F

08/13 22:05, , 3F
temp3=(0.64).ToInt32()=1 (進位了)
08/13 22:05, 3F

08/13 23:14, , 4F
如果你想要 temp3=0 的話,用 \ 來做除法
08/13 23:14, 4F

08/13 23:18, , 5F
\ 運算子: 相除並傳回整數結果。
08/13 23:18, 5F

08/14 00:03, , 6F
thx
08/14 00:03, 6F

08/14 00:03, , 7F
解決了> <
08/14 00:03, 7F
文章代碼(AID): #16m69f0l (Visual_Basic)