Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Created September 25, 2022 07:23
Show Gist options
  • Save LeanSeverino1022/e571517f53ad4273701f66c0121511d7 to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/e571517f53ad4273701f66c0121511d7 to your computer and use it in GitHub Desktop.
percent to decimal and vice-versa #numbers
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