added fraction support to round function

This commit is contained in:
Sergey Yuferev
2012-02-04 21:41:07 +04:00
committed by Luke Page
parent d81ba3bb38
commit 86520e53e8

View File

@@ -179,8 +179,15 @@ tree.functions = {
str = str.replace(/%%/g, '%');
return new(tree.Quoted)('"' + str + '"', str);
},
round: function (n) {
return this._math('round', n);
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" };
}
},
ceil: function (n) {
return this._math('ceil', n);