Last active
August 15, 2023 09:50
-
-
Save f1dz/039ebb2f710407f7283cfda05583e27c to your computer and use it in GitHub Desktop.
Dynamic Precision
This file contains hidden or 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
/** | |
* 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