How to convert percent to decimal in TypeScript

1 Answer

0 votes
function percentToDecimal(percent : any) {
    return parseFloat(percent) / 100.0;
}
 
console.log(percentToDecimal('58%')); 
console.log(percentToDecimal('0%')); 
console.log(percentToDecimal('17.5%')); 
console.log(percentToDecimal('100%'));
   
   
   
   
/*
run:
   
0.58
0 
0.175 
1 
   
*/

 



answered Apr 21, 2022 by avibootz
...