#4977: 執行結果是 0.59999999... 而不是 0.6


DaNee (DaNee)

學校 : 不指定學校
編號 : 18067
來源 : [163.22.154.62]
最後登入時間 :
2023-10-17 14:17:37
d018. 字串讀取練習 | From: [125.224.134.207] | 發表日期 : 2011-03-16 22:07

dim s as string
dim sp as integer
dim colon as integer
dim i as integer
dim n_str as string
dim total as double
dim num as double

open cons for input as #1
line input #1, s

while not eof(1)
  total = 0
  do
    sp = instr(s, " ")
    if sp > 0 then
      n_str = left(s, sp - 1)
      s = mid(s, sp + 1, len(s) - sp)
    else
      n_str = s
    end if

    i = val(left(n_str, 1))
    num = val(mid(n_str, 3, len(n_str) - 2))

    if i mod 2 = 1 then
      total = total + num
    else
      total = total - num
    end if
  loop until sp = 0

  print total
  line input #1, s
wend
 
 
請教一下,BASIC 有浮點數 fraction 處理的方式嗎?
 
 
#4980: Re:執行結果是 0.59999999... 而不是 0.6


YogiBear (test)

學校 : 國立臺中技術學院
編號 : 9150
來源 : [114.42.136.50]
最後登入時間 :
2024-06-13 13:21:11
d018. 字串讀取練習 | From: [122.117.89.202] | 發表日期 : 2011-03-17 14:44

dim s as string
dim sp as integer
dim colon as integer
dim i as integer
dim n_str as string
dim total as double
dim num as double

open cons for input as #1
line input #1, s

while not eof(1)
  total = 0
  do
    sp = instr(s, " ")
    if sp > 0 then
      n_str = left(s, sp - 1)
      s = mid(s, sp + 1, len(s) - sp)
    else
      n_str = s
    end if

    i = val(left(n_str, 1))
    num = val(mid(n_str, 3, len(n_str) - 2))

    if i mod 2 = 1 then
      total = total + num
    else
      total = total - num
    end if
  loop until sp = 0

  print total
  line input #1, s
wend
請教一下,BASIC 有浮點數 fraction 處理的方式嗎?

DIY 一下吧,一堆題目都要用到。 
ZeroJudge Forum