You have a number and you want to print it with thousands and decimals separators.
Use the number_format() function to format as an integer. By default, it rounds the number to the nearest integer.
Specify a numberof decimal places to format as a decimal.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"> <head> <title>Formatting Numbers</title> <meta Name="Author" Content="Hann So"> </head> <body> <p> <?php $num = 12345.67; echo "format $num: ", number_format($num), "<br />"; echo "format $num with 2 decimals: ", number_format($num, 2), "<br />"; ?> </p> </body> </html> |