Created
September 25, 2022 07:23
-
-
Save LeanSeverino1022/e571517f53ad4273701f66c0121511d7 to your computer and use it in GitHub Desktop.
percent to decimal and vice-versa #numbers
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 pctToDecimal(percent) { | |
return parseFloat(percent) / 100; | |
} | |
/* | |
pctToDecimal("2xx%") | |
0.02 | |
pctToDecimal("xx%") | |
NaN | |
pctToDecimal("50") | |
0.5 | |
pctToDecimal("5") | |
0.05 | |
*/ | |
function decimalToPercent(val) { | |
return parseFloat(val) * 100; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment