Created
September 15, 2020 03:29
-
-
Save if540/d6b64802916e58e485727cd81fc90d0e to your computer and use it in GitHub Desktop.
去零
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 {number} value 輸入 | |
* @param {number} position 小數點第 N 位 | |
*/ | |
function zeroDisplay (value, position = 2) { | |
let number = value * 1 | |
return isNaN(number) ? 0 : parseFloat(number.toFixed(position)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment