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
  • 181,601
  • 45
  • 354
  • 430
Modelesq
  • 4,850
  • 17
  • 57
  • 82

1 Answers1

1

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

var str = percent.toFixed(1) + '%';
Daniel A. White
  • 181,601
  • 45
  • 354
  • 430