ok, I change float to float32
    
    
    import std/math
    
    var
      fahr, celsius: float32
      low, up, step: float32
    
    low = 0.0   # from 0
    up = 300.0  # to 300
    step = 20.0 # with step 20
    
    echo "Fahrenheit   Celsius"
    
    while fahr <= up:
      celsius = round( (5.0 / 9.0) * (fahr - 32.0), 1)
      echo fahr, "   ", celsius
      fahr = fahr + step
    
    echo "done!"
    
    
    Run

and got output
    
    
    ./program_nim
    Fahrenheit   Celsius
    0.0   -17.79999923706055
    20.0   -6.699999809265137
    40.0   4.400000095367432
    60.0   15.60000038146973
    80.0   26.70000076293945
    100.0   37.79999923706055
    120.0   48.90000152587891
    140.0   60.0
    160.0   71.09999847412109
    180.0   82.19999694824219
    200.0   93.30000305175781
    220.0   104.4000015258789
    240.0   115.5999984741211
    260.0   126.6999969482422
    280.0   137.8000030517578
    300.0   148.8999938964844
    done!
    
    
    Run

(((

* * *

Calonger, ty! formatFloat works fine! ))) yahoooo
    
    
    import std/[math, strutils]
    
    #[
    iterator countup2*(a: float, b: float, step = 1.0): float {.inline.} =
      var res:float = a
      while res <= b:
        yield res
        res += step
    ]#
    
    var
      #celsius: float
      fahr, celsius: float
      low, up, step: float
    
    low = 0.0   # from 0
    up = 300.0  # to 300
    step = 20.0 # with step 20
    
    echo "Fahrenheit   Celsius"
    
    #for fahr in countup2(low, up, step):
    while fahr <= up:
      celsius = (5.0 / 9.0) * (fahr - 32.0)
      echo fahr, "   ", celsius.formatFloat(ffDecimal, 1)
      fahr = fahr + step
    
    echo "done!"
    
    
    Run

ty, question closed :)

Reply via email to