★ wanayoo — archive 1999 http://www.php.net/manual/function.number-format.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Math.
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Math.
* abs
* acos
* asin
* atan
* atan2
* base_convert
* bindec
* ceil
* cos
* decbin
* dechex
* decoct
* deg2rad
* exp
* floor
* getrandmax
* hexdec
* log
* log10
* max
* min
* mt_rand
* mt_srand
* mt_getrandmax
* number_format
* octdec
* pi
* pow
* rad2deg
* rand
* round
* sin
* sqrt
* srand
* tan
Manual: number_format
View the source code for this pageSearch the site



Previous page
 mt_getrandmax
 Updated
Sat, 12 Aug 2000
octdec 
Next page


number_format

(PHP3 , PHP4 )

number_format -- Format a number with grouped thousands

Description

string number_format (float number, int decimals, string dec_point, string thousands_sep)

Number_format() returns a formatted version of number. This function accepts either one, two or four parameters (not three):

If only one parameter is given, Number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.


User Contributed Notes: number_format


justin@visunet.ie
18-Jun-1999 05:21
Oops! That should be..
<pre>
$my_float = 2.683526;
$new_number = number_format($my_float,2)
echo $new_number;
</pre>
The result would be.. 2.68



jslatternboy@hotmail.com
30-Nov-1999 06:20
Surrogates of the comma and decimal point may not be strings. Id est:

$NUMBER = number_format(200000, 2, "CHICKEN", "JOHNNY");

print $NUMBER;

The first line will be interpreted as having two parameters: the number itself and the number of decimal spaces beyond the decimal point.

The second line will output so:

200,000.00



zhilin@188.net
21-Dec-1999 01:42
<PRE>$nn=number_format(200000.566,0);</PRE>
return "200,001"<pre>
$nn2=number_format(200000.3001,0);
</pre>return "200,000"



daantje@g-art.nl
19-Feb-2000 06:37
<PRE>
$TOTAL=150075.7;
echo "Total: \$".number_format($TOTAL,2,',','.');
</PRE>
results in:

Total: $150.075,70



mg@thepump.com
22-Apr-2000 02:13
to turn variable $Var = '324' into 324.00 or $Var = '324.9' into 324.90 or $Var = 324.914 into 324.91, use:
<PRE>
Number_Format($Var, 2);
</PRE>



haden@libero.it
06-Jul-2000 11:09
For a number in Italian LIRE style:
&lt;?
$PREZZO=1000000;
$LIRE=number_format($PREZZO,0,".",".");
echo $LIRE;
?>
output: 1.000.000

excused the repetition



chp@bitbybit.dk
12-Jul-2000 03:53
The arguments in the function definition
should read:

(float number [, int decimals[, string dec_point, string thousands_sep]])




david@php.net
30-Jul-2000 01:03
You can't have an empty thousands separator yet. This functionality is in 4.0.2, where you can just set it to "".


markus.brachner@net-inside.at
02-Aug-2000 06:23
If you want to work around the thousands-separator-bug/feature where you can't format a number without thousand separators use str_replace("A","",number_format($number,2,".","A"))


 About Notes


Previous page
 mt_getrandmax
 Updated
Sat, 12 Aug 2000
octdec 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.