lundi 2 novembre 2020

How to formatted a PHP float number like "00.00" pattern?

I have a student's marks between (0 to 20), i want to formatted as a float like this pattern "00.00".

example:

  • 12.5 ==> 12.50
  • 3.45 ==> 03.45
  • 12.4689 ==> 12.46
  • 0.752 ==> 00.75

this some code witch i try, but no result as i expected!

$output= round($number,2,PHP_ROUND_HALF_DOWN);

$output= sprintf('%00.02f',$number);

$output= str_pad($number,5,'0',STR_PAD_LEFT);

Aucun commentaire:

Enregistrer un commentaire