Dave's Brain

Browse - programming tips - javascript blank pad

Date: 2008may13
Language: javaScript

Q. javaScript has no sprintf() ... how can I blank pad a number?

A.  Use this function:

// n = number you want padded
// digits = length you want the final output
function blankPad(n, digits) {
	n = n.toString();
	while (n.length < digits) {
		n = ' ' + n;
	}
	return n;
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.