I am writing as I want y'all opinions and ideas that you can contribute towards my countdown script. It's count to 0.5sec accuracy.

So here the code.

function countdown(timeInSec)
	local sec = timeInSec
	while sec > 0 do
		wait(.1)
		sec = sec-0.1
		
		print(sec) -- Here is the problem.
	end
	
end
--Here is the output
--[[
1
0.90000000000002 -- It went fine until it reached 0.9 and started doing this.
0.80000000000002
0.70000000000002
0.60000000000002
0.50000000000002
0.40000000000002
0.30000000000002
0.20000000000002
0.10000000000002
1.8790524691781e-14
]]--

Can anyone find a way around this? Any help would be appreciated thank you. :D

1 comment

0

for i = 10,1 do i = i - 1 print(i/10) end <-- this rounds the number whole.