0

I have a variable that looks like this:

const percent = (props.students.length / totalStudentsProgram) * 100;

It returns 44.444444444444% How can I round it so that it looks like 44.4%

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Modelesq
  • 5,192
  • 20
  • 61
  • 88

1 Answers1

1

Call .toFixed will return a string with the appropriate number of decimal places.

var str = percent.toFixed(1) + '%';
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445