From 033abfd8bedf9d6f235a11703fc215bc65f1aeec Mon Sep 17 00:00:00 2001 From: Luke Page Date: Tue, 11 Dec 2012 20:47:17 +0000 Subject: [PATCH] do not divide by 100 when doing maths and keeping the %. Fixes #1069 --- lib/less/functions.js | 16 +++++----------- test/css/functions.css | 3 +++ test/less/functions.less | 3 +++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index 61b3ce4b..975393b5 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -214,25 +214,19 @@ tree.functions = { }, round: function (n, f) { var fraction = typeof(f) === "undefined" ? 0 : f.value; - if (n instanceof tree.Dimension) { - return new(tree.Dimension)(number(n).toFixed(fraction), n.unit); - } else if (typeof(n) === 'number') { - return n.toFixed(fraction); - } else { - throw { type: "Argument", message: "argument must be a number" }; - } + return this._math(function(num) { return num.toFixed(fraction); }, n); }, ceil: function (n) { - return this._math('ceil', n); + return this._math(Math.ceil, n); }, floor: function (n) { - return this._math('floor', n); + return this._math(Math.floor, n); }, _math: function (fn, n) { if (n instanceof tree.Dimension) { - return new(tree.Dimension)(Math[fn](number(n)), n.unit); + return new(tree.Dimension)(fn(parseFloat(n.value)), n.unit); } else if (typeof(n) === 'number') { - return Math[fn](n); + return fn(n); } else { throw { type: "Argument", message: "argument must be a number" }; } diff --git a/test/css/functions.css b/test/css/functions.css index 0b80cfe7..21fbb9c3 100644 --- a/test/css/functions.css +++ b/test/css/functions.css @@ -54,6 +54,9 @@ rounded-two: 10.67; roundedpx: 3px; roundedpx-three: 3.333px; + rounded-percentage: 10%; + ceil: 11px; + floor: 12px; percentage: 20%; color: #ff0011; tint: #898989; diff --git a/test/less/functions.less b/test/less/functions.less index 41244fbf..4ea1fc97 100644 --- a/test/less/functions.less +++ b/test/less/functions.less @@ -60,6 +60,9 @@ rounded-two: round(@r/3, 2); roundedpx: round(10px / 3); roundedpx-three: round(10px / 3, 3); + rounded-percentage: round(10.2%); + ceil: ceil(10.1px); + floor: floor(12.9px); percentage: percentage(10px / 50); color: color("#ff0011"); tint: tint(#777777, 13);