Timer counting problem

I have a problem with just a simple counter. It counts each 100milliseconds and add 0.1 to the text and show on the simulator.
However when the 54th seconds show up, it gives many zeros. Troubleshooting it and found that the system somehow added a 0.000000000001 to the value. Pls help ~

Code:

countUpTime = 0

local timeCounter = display.newText(countUpTime, 0, 0, native.systemFont, 32*2)
timeCounter:setTextColor( 255,0,0 )
timeCounter:setReferencePoint(display.TopLeftReferencePoint)
timeCounter.x = 100
timeCounter.y = 100

local function countTimer()
countUpTime = countUpTime + 0.1
timeCounter.text = countUpTime
print(countUpTime)
end

timer.performWithDelay (100, countTimer, 0) [import]uid: 59657 topic_id: 26156 reply_id: 326156[/import]

Here you go:

[code]
countUpTime = 0

local timeCounter = display.newText(countUpTime, 0, 0, native.systemFont, 32*2)
timeCounter:setTextColor( 255,0,0 )
timeCounter:setReferencePoint(display.TopLeftReferencePoint)
timeCounter.x = 100
timeCounter.y = 100

local function countTimer()
countUpTime = countUpTime + 0.1
timeCounter.text = string.format("%0.01f", tostring(countUpTime))
print(countUpTime)
end

timer.performWithDelay (10, countTimer, 0)
[/code] [import]uid: 84637 topic_id: 26156 reply_id: 106078[/import]

Hi Danny,

Many thanks!
This solution is somehow a work around method. It does solve my current problem I have in my game.

But using the print() statement the value shown in the terminal output actually still showing the fractional numbers. On the 84th seconds it adds a 0.09999999999999 to the value.

Where are these fractional values actually come from?
[import]uid: 59657 topic_id: 26156 reply_id: 106112[/import]

This is a floating point number thing. Computers don’t represent floating point numbers exactly.

Tiny rounding errors make it so that 20 additions of +0.05 does not result in precisely 1.0 for instance.

Check this out for more info: http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html

if you want to avoid the mess however you can do:

print(math.round(countUpTime)) [import]uid: 84637 topic_id: 26156 reply_id: 106575[/import]