PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO FORMAT NUMBERS IN PHP USING THE number_format() FUNCTION

Using the number_format() function, you can control how PHP displays your numbers on screen. The general format of use of the functions is as follows:

number_format (number, decimals , dec_point , thousands_sep);

number: The actual number being formatted.
decimals: How many decimal places.
dec_point: What character to use as separator. Default is decimal point (.).
thousands_sep: What character to use as separator for thousands. Default is comma (,).

Example:

$number= 123456789;
$newNumber=number_format ($number, 2 , "." , ",");

echo $newNumber; // outputs 123,456,789.00

Simple example using just 2 parameters ie. the number to format and how many decimal places:

$number= 123;
$newNumber=number_format ($number, 2);

echo $newNumber; //outputs 123.00

Home | Privacy Policy | Terms Of Use | Contact Us