Skip to content

Instantly share code, notes, and snippets.

@ghostcode
Last active January 12, 2023 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghostcode/09d0039934bbb8f274832df256ac13ec to your computer and use it in GitHub Desktop.
Save ghostcode/09d0039934bbb8f274832df256ac13ec to your computer and use it in GitHub Desktop.
获取精度
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