mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-15 09:19:55 -04:00
Add optional precision argument to Base.formatFloat().
This commit is contained in:
parent
85d2700eb1
commit
80ffd41560
1 changed files with 4 additions and 2 deletions
|
@ -433,9 +433,11 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
* up to the amount of fractional digits.
|
* up to the amount of fractional digits.
|
||||||
*
|
*
|
||||||
* @param {Number} num the number to be converted to a string
|
* @param {Number} num the number to be converted to a string
|
||||||
|
* @param {Number} [precision=5] the amount of fractional digits.
|
||||||
*/
|
*/
|
||||||
formatFloat: function(num) {
|
formatFloat: function(num, precision) {
|
||||||
return (Math.round(num * 100000) / 100000).toString();
|
precision = precision ? Math.pow(10, precision) : 100000;
|
||||||
|
return (Math.round(num * precision) / precision);
|
||||||
},
|
},
|
||||||
|
|
||||||
toFloat: function(str) {
|
toFloat: function(str) {
|
||||||
|
|
Loading…
Reference in a new issue