Prototype: Add Number.prototype.round as an alias to Math.round(). [Thomas Fuchs]

This commit is contained in:
Thomas Fuchs 2007-06-06 12:08:15 +00:00
parent 431dd4e994
commit 225597cb35
3 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Add Number.prototype.round as an alias to Math.round(). [Thomas Fuchs]
* Test library fixes: make rake dist work on Windows, only teardown if a browser is supported. Closes #8463, #8498. [Mislav Marohnić, grant]
* Change Element.insert syntax to allow multiple positions. [Thomas Fuchs]

View File

@ -114,6 +114,10 @@ Object.extend(Function.prototype, {
Function.prototype.defer = Function.prototype.delay.curry(0.01);
Object.extend(Number.prototype, {
round: function() {
return Math.round(this);
},
toColorPart: function() {
return this.toPaddedString(2, 16);
},

View File

@ -218,6 +218,13 @@
}
},
testNumberRound: function() {with(this) {
assertEqual(1, (0.9).round());
assertEqual(-2, (-1.9).round());
assertEqual(Math.round(Math.PI), Math.PI.round());
}},
testNumberToColorPart: function() {with(this) {
assertEqual('00', (0).toColorPart());
assertEqual('0a', (10).toColorPart());