<HTML ><HEAD ><TITLE >number_format</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="String functions" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="nl2br" HREF="function.nl2br.html"><LINK REL="NEXT" TITLE="ord" HREF="function.ord.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.nl2br.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ord.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.number-format" ></A >number_format</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN90249" ></A ><P > (PHP 3, PHP 4 )</P >number_format -- Format a number with grouped thousands</DIV ><DIV CLASS="refsect1" ><A NAME="AEN90252" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >number_format</B > ( float number [, int decimals [, string dec_point [, string thousands_sep]]])<BR ></BR ><P > <B CLASS="function" >number_format()</B > returns a formatted version of <TT CLASS="parameter" ><I >number</I ></TT >. This function accepts either one, two or four parameters (not three): </P ><P >If only one parameter is given, <TT CLASS="parameter" ><I >number</I ></TT > will be formatted without decimals, but with a comma (",") between every group of thousands. </P ><P > If two parameters are given, <TT CLASS="parameter" ><I >number</I ></TT > will be formatted with <TT CLASS="parameter" ><I >decimals</I ></TT > decimals with a dot (".") in front, and a comma (",") between every group of thousands. </P ><P > If all four parameters are given, <TT CLASS="parameter" ><I >number</I ></TT > will be formatted with <TT CLASS="parameter" ><I >decimals</I ></TT > decimals, <TT CLASS="parameter" ><I >dec_point</I ></TT > instead of a dot (".") before the decimals and <TT CLASS="parameter" ><I >thousands_sep</I ></TT > instead of a comma (",") between every group of thousands. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Only the first character of <TT CLASS="parameter" ><I >thousands_sep</I ></TT > is used. For example, if you use <TT CLASS="literal" >foo</TT > as <TT CLASS="parameter" ><I >thousands_sep</I ></TT > on the number <TT CLASS="literal" >1000</TT >, <B CLASS="function" >number_format()</B > will return <TT CLASS="literal" >1f000</TT >. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN90291" ></A ><P ><B >Example 1. <B CLASS="function" >number_format()</B > Example</B ></P ><P > For instance, French notation usually use two decimals, comma (',') as decimal separator, and space (' ') as thousand separator. This is achieved with this line : </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $number = 1234.56; // english notation (default) $english_format_number = number_format($number); // 1,234 // French notation $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,56 $number = 1234.5678; // english notation without thousands seperator $english_format_number = number_format($number, 2, '.', ''); // 1234.57 ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also: <A HREF="function.sprintf.html" ><B CLASS="function" >sprintf()</B ></A >, <A HREF="function.printf.html" ><B CLASS="function" >printf()</B ></A > and <A HREF="function.sscanf.html" ><B CLASS="function" >sscanf()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.nl2br.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ord.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >nl2br</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ord</TD ></TR ></TABLE ></DIV ></BODY ></HTML >