prototype/src/lang/number.js

52 lines
1006 B
JavaScript
Raw Normal View History

2008-09-29 21:06:54 +00:00
Object.extend(Number.prototype, (function() {
function toColorPart() {
return this.toPaddedString(2, 16);
2008-09-29 21:06:54 +00:00
}
2008-09-29 21:06:54 +00:00
function succ() {
return this + 1;
2008-09-29 21:06:54 +00:00
}
2008-09-29 21:06:54 +00:00
function times(iterator, context) {
2008-05-05 13:17:08 +00:00
$R(0, this, true).each(iterator, context);
return this;
2008-09-29 21:06:54 +00:00
}
2008-09-29 21:06:54 +00:00
function toPaddedString(length, radix) {
var string = this.toString(radix || 10);
return '0'.times(length - string.length) + string;
2008-09-29 21:06:54 +00:00
}
2008-09-29 21:06:54 +00:00
function toJSON() {
return isFinite(this) ? this.toString() : 'null';
}
2008-09-29 21:06:54 +00:00
function abs() {
return Math.abs(this);
}
function round() {
return Math.round(this);
}
function ceil() {
return Math.ceil(this);
}
function floor() {
return Math.floor(this);
}
return {
toColorPart: toColorPart,
succ: succ,
times: times,
toPaddedString: toPaddedString,
toJSON: toJSON,
abs: abs,
round: round,
ceil: ceil,
floor: floor
};
})());