MZ Always show double digits when displaying a variable number

Maybe this is a dumb question, but is there any easy way to always show double digits? For example: instead of 5, show 05

So, i'm making a custom clock system that get your PC time, but I can't find an easy way of always showing two digits, even when the variable is only 1 digit

The only way i found was with conditional branch: if <10 then change the entire text with a 0 behind the "\v[x]", like in the picture example, but this is kinda annoying since i have to make multiple versions of the text everytime i display this variable
(btw, in the example i only used for the hour variable)
Hi there!

You can use javascript to make that happen. Just take a number, turn it into a string and use the method padStart:
JavaScript:
const myNum = 2
String(myNum).padStart(2, 0)
// Output: 02

More detailed explanation:
I don't know exactly how are you eventing that. But on your place, besides having one variable to handle each time unit(seconds, minutes etc..) I would have a single variable to display all time units together. Example:

1776968585054.png

JavaScript:
const hour = String($gameVariables.value(35)).padStart(2, 0)
const minutes = String($gameVariables.value(34)).padStart(2, 0)
const seconds = String($gameVariables.value(33)).padStart(2, 0)
const allTimeVarId = 36

const timeText = hour + ":" + minutes + ":" + seconds
$gameVariables.setValue(allTimeVarId, timeText)

1776968613147.png
Hi there!

You can use javascript to make that happen. Just take a number, turn it into a string and use the method padStart:
JavaScript:
const myNum = 2
String(myNum).padStart(2, 0)
// Output: 02

More detailed explanation:
I don't know exactly how are you eventing that. But on your place, besides having one variable to handle each time unit(seconds, minutes etc..) I would have a single variable to display all time units together. Example:

View attachment 364921
JavaScript:
const hour = String($gameVariables.value(35)).padStart(2, 0)
const minutes = String($gameVariables.value(34)).padStart(2, 0)
const seconds = String($gameVariables.value(33)).padStart(2, 0)
const allTimeVarId = 36

const timeText = hour + ":" + minutes + ":" + seconds
$gameVariables.setValue(allTimeVarId, timeText)

View attachment 364922
Omg thank you so much, this helped a lot!

Original thread: https://forums.rpgmakerweb.com/threads/always-show-double-digits-when-displaying-a-variable-number.183354/