Santhosh
Santhosh

Reputation: 11774

lua number format not working

I have the following function:

function timestamp(duration)
    local hours = duration / 3600
    local minutes = duration % 3600 / 60
    local seconds = duration % 60
    return string.format("%02d:%02d:%02.03f", hours, minutes, seconds)
end

when the duration is 4.404 sec it returns 00:00:4.404

what is am looking for is 00:00:04.404

Upvotes: 0

Views: 215

Answers (1)

Aki
Aki

Reputation: 2928

It should be:

string.format("%02d:%02d:%06.3f", hours, minutes, seconds)

Field width contains all characters of the number, including point and fraction.

Upvotes: 3

Related Questions