PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I format a number with commas like a monetary value?


One of the great things about PHP is that there is a built in function to do most common tasks and save you writing a custom function to do it instead.

One such example of this is with regard number formatting, for instance if you want to turn this:
123456789
into this:
123,456,789

PHP will take care of this with the number_format function:

<?php
$value 
123456789;
echo 
number_format($value);
?>


Which will print to the screen just what you want: '123,456,789'



More numbers PHP Questions

How do I work out the remainder of a division?
How do I force a value to be treated as a number?
How do I generate a random number?
How do I round down a number?
How do I round up a number?