Skip to content

Instantly share code, notes, and snippets.

@f1dz
Last active August 15, 2023 09:50
Show Gist options
  • Save f1dz/039ebb2f710407f7283cfda05583e27c to your computer and use it in GitHub Desktop.
Save f1dz/039ebb2f710407f7283cfda05583e27c to your computer and use it in GitHub Desktop.
Dynamic Precision
/**
* Created by Chabib Nurozak
*/
function dynamicPrecision(value){
let secondNumbers = (value.toString().split('.')[1]).split('');
let i = 1;
for(let num in secondNumbers){
if(num > 0) break;
i++;
}
return value.toPrecision(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment