Formatted numeric output
Express a number in decimal as a fixed-length string with leading zeros.
Formatted numeric output
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
JavaScript
var n = 123 var str = ("00000"+m).slice(-5) alert(str) //or, put in browser URL: javascript:n=123;alert(("00000"+n).slice(-5))
Python
#tested in Python 2.4.1 n = 123 str = "%05d" % n #5 places wide, leading zeros print n, str #output: 123 00123
SQL
--Tested MS SQL 2005 declare @n int select @n=123 select substring(convert(char(5), 10000+@n),2,4) as Answer --Output: 0123