Reply
Padding numbers to a specified length with leading zeros.
Replies: 0   Views: 1196  Subscribers: 0

Posted by reece · 30-06-2012 - 22:34

Edited by reece · 12-11-2012 - 05:02
A quick approach i developed in javascript to pad numbers with leading zeros.

­
//
// Ensure number is expressed with padded 0 digits to the length of len.
//
function paddedNumber(num, len) {
	return (num.length >= len) ? num : this.paddedNumber('0' + num, len);
}­