0

I have a value $rating that is between 0.00 and 10.00.

I need to add trailing zeroes to numbers like 3.70 (which is 3.7) and 5.00 (which is 5). Do I need some kind of if statement too to check what value $rating is and then do some kind of str_pad? I'm not sure what to do.

frosty
  • 2,779
  • 6
  • 34
  • 63

2 Answers2

1

See the number_format function

echo number_format(5, 2);    // returns 5.00
echo number_format(5.2, 2);  // returns 5.20
echo number_format(5.24, 2); // returns 5.24
pavel
  • 26,538
  • 10
  • 45
  • 61
0

Try number_format, something like this:

number_format((float)$yourNumber, 2, '.', '');
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45