Add optional digits precision to Base.formatNumber, default to 5.

This commit is contained in:
Jürg Lehni 2012-11-06 07:15:01 -08:00
parent 345309867e
commit ab633f15ac

View file

@ -196,10 +196,14 @@ this.Base = Base.inject(/** @lends Base# */{
/**
* Utility function for rendering numbers to strings at a precision of
* up to 5 fractional digits.
* up to the amount of fractional digits.
*
* @param {Number} num the number to be converted to a string
* @param {Number} [digits=5] the maximum maount of fraction digits
*/
formatNumber: function(num) {
return (Math.round(num * 100000) / 100000).toString();
formatNumber: function(num, digits) {
var factor = Math.pow(10, digits | 5);
return (Math.round(num * factor) / factor).toString();
}
}
});