October 02, 2009

Formatting Numbers in PHP Function number_format ()

Formatting Numbers in PHP Function number_format ()


number_format (n [, x [, y, z]);

type is a float or real, may also integer
x is the number of decimal digits behind the comma
y is the string as a decimal separator
z is the string as a separator groups per thousand
If only the parameter (n) is used, it will be formatted without decimals, and groups of thousands separated by ",".

If only the parameter (n) and (x) is used, it will be formatted with the decimal separator shape "." And the group of thousands separated by ",".

And if the four parameters are used, it will be formatted with the decimal separator and the y are separated by thousands of string written according to the parameters z.

example: 750250100.75045

<? php

$ number = 750250100.75045;

/ / Result 750,250,100
$ num = number_format ($ number);
echo $ num. "<br>";

/ / Result 750,250,100.55
$ num = number_format ($ number, 2);
echo $ num. "<br>";

/ / Result 750,250,100.55
$ num = number_format ($ number, 2, ",", ".");
echo $ num. "<br>";

/ / Result 250 # 750 # 100-55
$ num = number_format ($ number, 2, "-", "#");
echo $ num. "<br>";

$ num = number_format ($ number, 0, ",", ".");
echo "Rp.". .",-"; $ num / / Result Rp. 750,250,100, --

?>

No comments:

Post a Comment

Let's us sharing

Recent Comment

Grab This Widget