phaser/src/math/RoundTo.js

30 lines
772 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2017-10-06 03:52:41 +00:00
/**
* Round a value to a given decimal place.
2017-10-06 03:52:41 +00:00
*
* @function Phaser.Math.RoundTo
* @since 3.0.0
*
* @param {number} value - The value to round.
* @param {integer} [place=0] - The place to round to.
* @param {integer} [base=10] - The base to round in. Default is 10 for decimal.
2017-10-06 03:52:41 +00:00
*
* @return {number} The rounded value.
2017-10-06 03:52:41 +00:00
*/
var RoundTo = function (value, place, base)
{
if (place === undefined) { place = 0; }
if (base === undefined) { base = 10; }
var p = Math.pow(base, -place);
return Math.round(value * p) / p;
};
module.exports = RoundTo;