CopyPastehas never been so tasty!

Format an Integer and floating point values using number_for

by anonymous

  • 0
  • 0
  • 0

Orignal Source:


Integer values:


In PHP integer is single-value type. Integers are whole numbers. It range varies according to your platform. But you can use any number from -2,147,483,648 to +2,147,483,647. Integer can be written in decimal, octal and hexadecimal.


For example:

1998 (Decimal)
0755  (Octal) 


Floating-point values:


A floating-point is a representation of real numbers that can support wide range of values. PHP use IEEE 754 double precision format. Floating-point numbers have limited precision. Floating–point has decimal values and fractional part.


A floating-point numbers is also known as double, float or real numbers. The size of floating values depends upon the platform we use and also a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value.


For Example:


$a = 1.234;
$b = 1.2e3;
$c = 7E-10;


Number_format () function in php:


Number_format is a built-in function in php that was used to format the number in many ways, along with different options like how many decimal points it will have, choosing the 1000s, and decimal point dividers.




number_format (number,decimals, decimal point,separator)


Number: is used for input number. It is required.


Decimal: is used to refer the number of decimal points. It is optional.


Decimal point: is used to refer separator of decimal point. It is also optional.


Separator: is used to refer thousands separator. It is also optional.





$i = 123456;

$f = 98765.567;

$si = number_format($i, 0, ',', '.');

$sf = number_format($f, 2);

echo "\$si = $si and \$sf = $sf\n";



This is simple code for formation of number using Number_format () function in php.


This simple article tells that how we can format numbers using Number_format () function in php.

Add A Comment: