javascript - Show a leading zero if a number is less than 10 -


possible duplicate:
javascript equivalent printf/string.format
how can create zerofilled value using javascript?

i have number in variable:

var number = 5; 

i need number output 05:

alert(number); // want alert display 05, rather 5. 

how can this?

i manually check number , add 0 string, hoping there's js function it?

there's no built-in javascript function this, can write own easily:

function pad(n) {     return (n < 10) ? ("0" + n) : n; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -