Skip to content

Instantly share code, notes, and snippets.

@chiyoyo
Last active June 17, 2019 02:15
Show Gist options
  • Save chiyoyo/128f83e4bc5a9ace8221a8b6fa9776f7 to your computer and use it in GitHub Desktop.
Save chiyoyo/128f83e4bc5a9ace8221a8b6fa9776f7 to your computer and use it in GitHub Desktop.
小数点以下X桁を指定して四捨五入 ref: http://qiita.com/chiyoyo/items/eac6d7cb4d3d6a6ab3fb
/**
* 小数点以下の桁数
* @param {double} 数値
* @param {integer} 小数点以下の桁数(省略可能)
* @return {double} 四捨五入した値
*/
Math.round = function (round_original) {
return function (number, pricision) {
var _pow;
switch (arguments.length) {
case 1:
return round_original(number);
case 2:
_pow = Math.pow(10, pricision);
return round_original(number * _pow) / _pow;
}
}
}(Math.round);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment