number_format
Format a number in a thousand separator
number_format()
function formats numbers by grouping thousands of bits.
Note: This function supports one, two, or four parameters (not three).
Format numbers:
<?php echo number_format ( "5000000" ) . "<br>" ; echo number_format ( "5000000" , 2 ) . "<br>" ; echo number_format ( "5000000" , 2 , "," , "." ) ; ?>
Try it yourself
You want to return a price: One parameter will round the number (formatted with no decimal places), and two parameters give the result you want:
<?php $num = 4999.9 ; $formattedNum = number_format ( $num ) . "<br>" ; echo $formattedNum ; $formattedNum = number_format ( $num , 2 ) ; echo $formattedNum ; ?>
Try it yourself