From 225597cb358ece6acafc70cc6cf495ec08e656ee Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Wed, 6 Jun 2007 12:08:15 +0000 Subject: [PATCH] Prototype: Add Number.prototype.round as an alias to Math.round(). [Thomas Fuchs] --- CHANGELOG | 2 ++ src/base.js | 4 ++++ test/unit/base.html | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index e09c8fc..d4be416 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/src/base.js b/src/base.js index 2156fd7..ddef1c5 100644 --- a/src/base.js +++ b/src/base.js @@ -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); }, diff --git a/test/unit/base.html b/test/unit/base.html index 5741a85..c464b27 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -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());