.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Format 3pm" .TH Format 3pm "2011-07-11" "perl v5.12.4" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Locale::Currency::Format \- Perl functions for formatting monetary values .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Locale::Currency::Format; \& \& $amt = currency_format(\*(AqUSD\*(Aq, 1000); # => 1,000.00 USD \& $amt = currency_format(\*(AqEUR\*(Aq, 1000, FMT_COMMON); # => EUR1.000,00 \& $amt = currency_format(\*(AqUSD\*(Aq, 1000, FMT_SYMBOL); # => $1,000.00 \& \& $sym = currency_symbol(\*(AqUSD\*(Aq); # => $ \& $sym = currency_symbol(\*(AqGBP\*(Aq, SYM_HTML); # => £ \& \& $decimals = decimal_precision(\*(AqUSD\*(Aq); # => 2 \& $decimals = decimal_precision(\*(AqBHD\*(Aq); # => 3 \& \& $thou_sep = thousands_separator(\*(AqUSD\*(Aq); # => , \& $thou_sep = thousands_separator(\*(AqEUR\*(Aq); # => . \& \& $dec_sep = decimal_separator(\*(AqUSD\*(Aq); # => . \& $dec_sep = decimal_separator(\*(AqEUR\*(Aq); # => , \& \& currency_set(\*(AqUSD\*(Aq, \*(Aq#.###,## $\*(Aq, FMT_COMMON); # => set custom format \& currency_format(\*(AqUSD\*(Aq, 1000, FMT_COMMON); # => 1.000,00 $ \& currency_set(\*(AqUSD\*(Aq); # => reset default format .Ve .PP The following example illustrates how to use Locale::Currency::Format with Mason. Skip it if you are not interested in Mason. A simple Mason component might look like this: .PP .Vb 1 \& Total: <% 123456789, \*(Aqeur\*(Aq |c %> \& \& <%init> \& use Locale::Currency::Format; \& \& $m\->interp\->set_escape(c => \e&escape_currency); \& \& sub escape_currency { \& my ($amt, $code) = ${$_[0]} =~ /(.*?)([A\-Za\-z]{3})/; \& ${$_[0]} = currency_format($code, $amt, FMT_HTML); \& } \& .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBLocale::Currency::Format\fR is a light-weight Perl module that enables Perl code to display monetary values in the formats recognized internationally and/or locally. .ie n .IP """currency_format(CODE, AMOUNT [, FORMAT])""" 2 .el .IP "\f(CWcurrency_format(CODE, AMOUNT [, FORMAT])\fR" 2 .IX Item "currency_format(CODE, AMOUNT [, FORMAT])" \&\fBcurrency_format\fR takes two mandatory parameters, namely currency code and amount respectively, and optionally a third parameter indicating which format is desired. Upon failure, it returns \fIundef\fR and an error message is stored in \fB\f(CB$Locale::Currency::Format::error\fB\fR. .Sp .Vb 4 \& CODE \& A 3\-letter currency code as specified in ISO 4217. \& Note that old code such as GBP, FRF and so on can also \& be valid. \& \& AMOUNT \& A numeric value. \& \& FORMAT \& There are five different format options FMT_STANDARD, \& FMT_COMMON, FMT_SYMBOL, FMT_HTML and FMT_NAME. If it is \& omitted, the default format is FMT_STANDARD. \& \& FMT_STANDARD Ex: 1,000.00 USD, 1.000.000,00 EUR \& FMT_SYMBOL Ex: $1,000.00 \& FMT_COMMON Ex: 1.000 Dong (Vietnam), BEF 1.000 (Belgium) \& FMT_HTML Ex: £1,000.00 (pound\-sign HTML escape) \& FMT_NAME Ex: 1,000.00 US Dollar \& \& NOTE: By default the trailing zeros after the decimal \& point will be added. To turn it off, do a bitwise C \& of FMT_NOZEROS with one of the five options above. \& Ex: FMT_STANDARD | FMT_NOZEROS will give 1,000 USD .Ve .ie n .IP """currency_symbol(CODE [, TYPE])""" 2 .el .IP "\f(CWcurrency_symbol(CODE [, TYPE])\fR" 2 .IX Item "currency_symbol(CODE [, TYPE])" For conveniences, the function \fBcurrency_symbol\fR is provided for currency symbol lookup given a 3\-letter currency code. Optionally, one can specify which format the symbol should be returned \- Unicode-based character or \s-1HTML\s0 escape. Default is a Unicode-based character. Upon failure, it returns \fIundef\fR and an error message is stored in \fB\f(CB$Locale::Currency::Format::error\fB\fR. .Sp .Vb 2 \& CODE \& A 3\-letter currency code as specified in ISO 4217 \& \& TYPE \& There are two available types SYM_UTF and SYM_HTML \& SYM_UTF returns the symbol (if exists) as an Unicode \& character \& SYM_HTML returns the symbol (if exists) as a HTML escape .Ve .ie n .IP """decimal_precision(CODE)""" 2 .el .IP "\f(CWdecimal_precision(CODE)\fR" 2 .IX Item "decimal_precision(CODE)" For conveniences, the function \fBdecimal_precision\fR is provided to lookup the decimal precision for a given 3\-letter currency code. .Sp Upon failure, it returns \fIundef\fR and an error message is stored in \fB\f(CB$Locale::Currency::Format::error\fB\fR. .Sp .Vb 2 \& CODE \& A 3\-letter currency code as specified in ISO 4217 .Ve .ie n .IP """decimal_separator(CODE)""" 2 .el .IP "\f(CWdecimal_separator(CODE)\fR" 2 .IX Item "decimal_separator(CODE)" For conveniences, the function \fBdecimal_separator\fR is provided to lookup the decimal separator for a given 3\-letter currency code. .Sp Upon failure, it returns \fIundef\fR and an error message is stored in \fB\f(CB$Locale::Currency::Format::error\fB\fR. .Sp .Vb 2 \& CODE \& A 3\-letter currency code as specified in ISO 4217 .Ve .ie n .IP """thousands_separator(CODE)""" 2 .el .IP "\f(CWthousands_separator(CODE)\fR" 2 .IX Item "thousands_separator(CODE)" For conveniences, the function \fBthousands_separator\fR is provided to lookup the thousands separator for a given 3\-letter currency code. .Sp Upon failure, it returns \fIundef\fR and an error message is stored in \fB\f(CB$Locale::Currency::Format::error\fB\fR. .Sp .Vb 2 \& CODE \& A 3\-letter currency code as specified in ISO 4217 .Ve .ie n .IP """currency_set(CODE [, TEMPLATE, FORMAT])""" 2 .el .IP "\f(CWcurrency_set(CODE [, TEMPLATE, FORMAT])\fR" 2 .IX Item "currency_set(CODE [, TEMPLATE, FORMAT])" \&\fBcurrency_set\fR can be used to set a custom format for a currency instead of the provided format. For example, in many non-English speaking countries, the \s-1US\s0 dollars might be displayed as \fB2.999,99 $\fR instead of the usual \fB\f(CB$2\fB,999.99\fR. In order to accomplish this, one will need to do as follows: .Sp .Vb 1 \& use Locale::Currency::Format qw(:default $error); \& \& my $currency = \*(AqUSD\*(Aq; \& my $template = \*(Aq#.###,## $\*(Aq; \& if (currency_set($currency, $template, FMT_COMMON)) { \& print currency_format($currency, 2999.99, FMT_COMMON), "\en"; \& } \& else { \& print "cannot set currency format for $currency: $error\en"; \& } .Ve .Sp The arguments to \fBcurrency_set\fR are: .Sp .Vb 2 \& CODE \& A 3\-letter currency code as specified in ISO 4217 \& \& TEMPLATE \& A template in the form #.###,##$, #.### kr, etc. \& \& If a unicode character is used, make sure that \& the template is double\-quoted. \& Ex: currency_set(\*(AqGBP\*(Aq, "\ex{00A3}#,###.##", FMT_SYMBOL) \& \& If an HTML symbol is wanted, escape its equivalent HTML code. \& Ex: currency_set(\*(AqGBP\*(Aq, \*(Aq£#,###.##\*(Aq, FMT_HTML) \& \& FORMAT \& This argument is required if TEMPLATE is present. \& The formats FMT_SYMBOL, FMT_COMMON, FMT_HTML are accepted. \& \& NOTE! \& FMT_STANDARD and FMT_NAME will always be in the form \& such as 1,925.95 AUD. Hence, \& currency_set returns an error if FMT_STANDARD or FMT_NAME \& is specified as FORMAT. \& \& With FMT_COMMON, you can always achieve what you would \& have done with FMT_STANDARD and FMT_NAME, as follows \& \& my $amt = 1950.95; \& currency_set(\*(AqUSD\*(Aq, \*(AqUSD #.###,##\*(Aq, FMT_COMMON); \& print currency_format(\*(AqUSD\*(Aq, $amt, FMT_COMMON); # USD 1,950.95 \& currency_set(\*(AqUSD\*(Aq, \*(AqUS Dollar #.###,##\*(Aq, FMT_COMMON); \& print currency_format(\*(AqUSD\*(Aq, $amt, FMT_COMMON); # US Dollar 1,950.95 .Ve .Sp Invoking \fBcurrency_set\fR with one argument will reset all formats to their original settings. .Sp For example .Sp .Vb 1 \& currency_set(\*(AqUSD\*(Aq) .Ve .Sp will clear all previous custom settings for the \s-1US\s0 currency (ie. \s-1FMT_SYMBOL\s0, \s-1FMT_HTML\s0, \s-1FMT_COMMON\s0). .SS "A \s-1WORD\s0 \s-1OF\s0 \s-1CAUTION\s0" .IX Subsection "A WORD OF CAUTION" Please be aware that some currencies might have missing common format. In that case, \fBcurrency_format\fR will fall back to \fB\s-1FMT_STANDARD\s0\fR format. .PP Also, be aware that some currencies do not have monetary symbol. .PP As countries merge together or split into smaller ones, currencies can be added or removed by the \s-1ISO\s0. Please help keep the list up to date by sending your feedback to the email address at the bottom. .PP To see the error, examine \f(CW$Locale::Currency::Format::error\fR .PP .Vb 3 \& use Locale::Currency::Format; \& my $value = currency_format(\*(AqUSD\*(Aq, 1000); \& print $value ? $value : $Locale::Currency::Format::error \& \& OR \& \& use Locale::Currency::Format qw(:DEFAULT $error); \& my $value = currency_format(\*(AqUSD\*(Aq, 1000); \& print $value ? $value : $error .Ve .PP Lastly, please refer to perluniintro and perlunicode for displaying Unicode characters if you intend to use \fB\s-1FMT_SYMBOL\s0\fR and \fBcurrency_symbol\fR. Otherwise, it reads \*(L"No worries, mate!\*(R" .SH "SEE ALSO" .IX Header "SEE ALSO" Locale::Currency, Math::Currency, Number::Format, perluniintro, perlunicode .SH "BUGS" .IX Header "BUGS" If you find any inaccurate or missing information, please send your comments to tnguyen@cpan.org. Your effort is certainly appreciated! .SH "CONTRIBUTOR(S)" .IX Header "CONTRIBUTOR(S)" James Kiser .SH "AUTHOR" .IX Header "AUTHOR" Tan D Nguyen .SH "COPYRIGHT" .IX Header "COPYRIGHT" This library is free software. You may distribute under the terms of either the \s-1GNU\s0 General Public License or the Artistic License.