Last active
January 12, 2023 05:57
-
-
Save ghostcode/09d0039934bbb8f274832df256ac13ec 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
function getPrecision(value) { | |
const valueString = value.toString(); | |
if (valueString.indexOf('e-') >= 0) { | |
return parseInt(valueString.slice(valueString.indexOf('e-') + 2), 10); | |
} | |
let precision = 0; | |
if (valueString.indexOf('.') >= 0) { | |
precision = valueString.length - valueString.indexOf('.') - 1; | |
} | |
return precision; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment