Hi Folks,
Something to think about - maybe you will find it useful for game-development!
Number.prototype.addZeros = function(p) {
return new Array(p - length(this) + 1).join('0') + this;
};
// Usage:
points = 200;
trace(points.addZeros(10)); // result: 0000000200
or as a class:
Score = function (points) {
this.points = points;
};
Score.prototype.display = function(p) {
return new Array(p - length(this.points) + 1).join('0') + this.points;
};
myScore = new Score(200).display(10);
trace(myScore);
yours
Matze K.