Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get numbers to always display as two digits

Tags:

lua

coronasdk

I need to display a countdown that turns from 00:10 to 00:09 and not 00:9. How do I make sure that a given number displays with two digits without resorting to cumbersome if-statements?

like image 853
Ravn Avatar asked Jul 15 '13 09:07

Ravn


1 Answers

This is completely possible to do without an if statement, it's just string formatting...

local secondTime = 0
local minuteTime = 10
print(string.format("%02d:%02d",minuteTime,secondTime))
like image 75
catwell Avatar answered Nov 02 '22 07:11

catwell