Last active
June 17, 2019 02:15
-
-
Save chiyoyo/128f83e4bc5a9ace8221a8b6fa9776f7 to your computer and use it in GitHub Desktop.
小数点以下X桁を指定して四捨五入 ref: http://qiita.com/chiyoyo/items/eac6d7cb4d3d6a6ab3fb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 小数点以下の桁数 | |
* @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