Help with php number_format

Asked

Viewed 35 times

2

I have the following code:

$subjects[$i]['mark_final'] = number_format($final,1);

That returns example: 8.0 (so far everything ok).

The problem is when I divide by 4.

$subjects[$i]['mark_final'] = number_format($final, 1) / 4;

He returns me 2, I would like you to return 2.0

2 answers

2


Use the number_format after splitting, thus:

$subjects[$i]['mark_final'] = number_format(($final/4), 1);
  • It worked perfectly. Thank you very much. Jrd.

2

To get the return as a value float you can return like this:

$subjects[$i]['mark_final'] = number_format(($final / 4), 1, ".");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.