<?php
str money_format ( string $format , float $number )
where,
$format = The format specification
( SEE the below TABLES )
$number = The NUMBER to be formated
?>
FLAGS | MEANING | DEFAULT |
=f | The character = followed by a (single byte) character f to be used as the numeric fill character. | SPACE |
^ | Disable the use of grouping characters, (as defined by the current locale). | |
+ | Specify the formatting style for positive and negative numbers. If + is used, the locale's equivalent for + and - will be used. If ( is used, negative amounts are enclosed in parenthesis | + |
( | ||
! | Suppress the currency symbol from the output string. | |
- | If present, it will make all fields left-justified, (padded to the right), as opposed to the default which is for the fields to be right-justified, (padded to the left). | RIGHT |
ed48 |
FIELD WIDTH | MEANING | DEFAULT |
W | A decimal digit string specifying a minimum field width. Field will be right-justified unless the flag - is used. | 0 |
ed48 |
LEFT PRECISION | MEANING |
#n | The maximum number of digits (n) expected to the left of the decimal character (e.g. the decimal point). It is used usually to keep formatted output aligned in the same columns, using the fill character if the number of digits is less than n. If the number of actual digits is bigger than n, then this specification is ignored. If grouping has not been suppressed using the ^ flag, grouping separators will be inserted before the fill characters (if any) are added. Grouping separators will not be applied to fill characters, even if the fill character is a digit. To ensure alignment, any characters appearing before or after the number in the formatted output such as currency or sign symbols are padded as necessary with space characters to make their positive and negative formats an equal length. |
ed48 |
RIGHT PRECISION | MEANING |
.p | A period followed by the number of digits (p) after the decimal character. If the value of p is 0 (zero), the decimal character and the digits to its right will be omitted. If no right precision is included, the default will dictated by the current local in use. The amount being formatted is rounded to the specified number of digits prior to formatting. |
ed48 |
CONVERSION | MEANING | LOCALE |
i | The number is formatted according to the locale's international currency format. | INTERNATIONAL |
n | The number is formatted according to the locale's national currency forma. | REGIONAL |
ed48 |
THE CHARACTER | PERCENTAGE SYMBOL |
% | Returns the % character |
ed48 |
<?php
if (!function_exists('money_format'))
{
echo 'FUNCTION NOT AVAILABLE IN THIS ENVIRONMENT';
}
else
{
$generic_money01 = 1234.56;
setlocale (LC_MONETARY, 'pt_BR', 'pt-BR');
echo 'pt_BR<br><br>';
$br_money01a =
money_format('%i', $generic_money01);
$br_money01b =
money_format('%(#8n', $generic_money01);
$br_money01c =
money_format('%^(#8n', $generic_money01);
$br_money01d =
money_format('%=0(#10.2i', $generic_money01);
echo $br_money01a . "<br><br>";
echo $br_money01b . "<br><br>";
echo $br_money01c . "<br><br>";
echo $br_money01d . "<br><br><br><br>";
setlocale (LC_MONETARY, 'pt_PT', 'pt-PT');
echo 'pt_PT<br><br>';
$pt_money01a =
money_format('%i', $generic_money01);
$pt_money01b =
money_format('%(#8n', $generic_money01);
$pt_money01c =
money_format('%^(#8n', $generic_money01);
$pt_money01d =
money_format('%=0(#10.2i', $generic_money01);
echo $pt_money01a . "<br><br>";
echo $pt_money01b . "<br><br>";
echo $pt_money01c . "<br><br>";
echo $pt_money01d . "<br><br><br><br>";
setlocale (LC_MONETARY, "en_US", "en-US");
echo 'en_US<br><br>';
$us_money01a =
money_format('%i', $generic_money01);
$us_money01b =
money_format('%(#8n', $generic_money01);
$us_money01c =
money_format('%^(#8n', $generic_money01);
$us_money01d =
money_format('%=0(#10.2i', $generic_money01);
echo $us_money01a . "<br><br>";
echo $us_money01b . "<br><br>";
echo $us_money01c . "<br><br>";
echo $us_money01d . "<br><br><br><br>";;
$yourlocale =
Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
setlocale (LC_MONETARY, "$yourlocale");
echo $yourlocale . ' (YOUR LOCALE)<br><br>';
$lc_money01a =
money_format('%i', $generic_money01);
$lc_money01b =
money_format('%(#8n', $generic_money01);
$lc_money01c =
money_format('%^(#8n', $generic_money01);
$lc_money01d =
money_format('%=0(#10.2i', $generic_money01);
echo $lc_money01a . "<br><br>";
echo $lc_money01b . "<br><br>";
echo $lc_money01c . "<br><br>";
echo $lc_money01d;
}
?>