Skip to content

Commit

Permalink
add toFixed()
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkueng committed Aug 31, 2015
1 parent 2ca7390 commit 95c1924
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
Expand Up @@ -789,6 +789,27 @@ Victor.prototype.unfloat = function () {
return this;
};

/**
* Rounds both axis to a certain precision
*
* ### Examples:
* var vec = new Victor(100.2, 50.9);
*
* vec.unfloat();
* vec.toString();
* // => x:100, y:51
*
* @param {Number} Precision (default: 8)
* @return {Victor} `this` for chaining capabilities
* @api public
*/
Victor.prototype.toFixed = function (precision) {
if (typeof precision === 'undefined') { precision = 8; }
this.x = this.x.toFixed(precision);
this.y = this.y.toFixed(precision);
return this;
};

/**
* Performs a linear blend / interpolation of the X axis towards another vector
*
Expand Down

0 comments on commit 95c1924

Please sign in to comment.