0

Here is a simplified version of my code:

percentage = 0
downloaded = 0
fileSize = 10000
while percentage <= 1
  downloaded += 1
  percentage = downloaded/fileSize
  sleep(0.1)
  print " Does not change: #{downloaded/fileSize}, Does not change: #{percentage}, Does change: #{downloaded}\r"
end

The #{downloaded/fileSize} and the #{percentage} does not change in the loop. Whilst the variable, downloaded, is actually changing in #{downloaded}. Why is #{downloaded/fileSize}, and #{percentage}, not changing in the print statement and how can I change this?

The "\r" makes it print on the same line, but removing it doesn't make the print statement work as expected.

Jordan Stewart
  • 3,187
  • 3
  • 25
  • 37

1 Answers1

0

Ruby is doing integer maths it works with:

percentage = Float(0)
downloaded = Float(0)
fileSize = Float(10000)
Jordan Stewart
  • 3,187
  • 3
  • 25
  • 37