mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Add optional digits precision to Base.formatNumber, default to 5.
This commit is contained in:
parent
345309867e
commit
ab633f15ac
1 changed files with 7 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue