do not divide by 100 when doing maths and keeping the %. Fixes #1069

This commit is contained in:
Luke Page
2012-12-11 20:47:17 +00:00
parent abb6b999c6
commit 033abfd8be
3 changed files with 11 additions and 11 deletions

View File

@@ -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" };
}