Created
September 15, 2020 03:28
-
-
Save if540/0c3c8ac084146787145ee3f9fbd15ac2 to your computer and use it in GitHub Desktop.
取小數點第 N 位
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
/** | |
* 取小數點第 N 位 | |
* @summary 末位四捨五入 | |
* @param {number} value 輸入 | |
* @param {number} position 小數點第 N 位 | |
*/ | |
function toPointFixed (value, position) { | |
const decimalType = 10 | |
let decimalNumber = Math.pow(decimalType, position) | |
return Math.round(value * decimalNumber) / decimalNumber | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment