0

I have a $total with a value of 1400 which I'm trying to echo as 1,400.00 however sprintf and number_format refuse to cooperate with each other. How do I properly format the $total to echo as 1,400.00?

<?php
$total = 1400;
echo sprintf('%0.2f',$total);
//'1400.00'

echo number_format($total);
//'1,400'

echo sprintf('%0.2f',number_format($total_grand));
//'1.00'

echo number_format(sprintf('%0.2f',$total));
//'1,400'
?>
John
  • 11,516
  • 11
  • 87
  • 151

1 Answers1

1

This should suffice:

$total = 1400;        
echo number_format($total,2);

This will output:

1,400.00

See: number_format()

KIKO Software
  • 12,609
  • 2
  • 15
  • 29