How to convert fraction to decimal in JavaScript

1 Answer

0 votes
function fractionToDecimal(fraction) {
	const arr = fraction.split('/');
	const decimal = arr[0] / arr[1];

    return decimal;
}

console.log(fractionToDecimal('1/2')); 
console.log(fractionToDecimal('1/3')); 
console.log(fractionToDecimal('1/4')); 
console.log(fractionToDecimal('1/5'));


  
  
  
  
/*
run:
  
0.5
0.3333333333333333
0.25
0.2
  
*/

 



answered Apr 21, 2022 by avibootz

Related questions

...