.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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" '' . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Format 3pm" .TH Format 3pm "2022-06-17" "perl v5.34.0" "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" Template::Plugin::Number::Format \- Plugin/filter interface to Number::Format .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& [% USE Number.Format %] \& [% num | format_number %] .Ve .SH "ABSTRACT" .IX Header "ABSTRACT" Template::Plugin::Number::Format makes the number-munging grooviness of Number::Format available to your templates. It is used like a plugin, but installs filters into the current context. .SH "DESCRIPTION" .IX Header "DESCRIPTION" All filters created by Template::Plugin::Number::Format can be configured by constructor options and options that can be passed to individual filters. See \*(L"\s-1METHODS\*(R"\s0 in Number::Format for all the details. .SS "Constructor Parameters" .IX Subsection "Constructor Parameters" The \s-1USE\s0 line accepts the following parameters, all optional, which define the default behavior for filters within the current Context: .IP "\s-1THOUSANDS_SEP\s0" 4 .IX Item "THOUSANDS_SEP" character inserted between groups of 3 digits .IP "\s-1DECIMAL_POINT\s0" 4 .IX Item "DECIMAL_POINT" character separating integer and fractional parts .IP "\s-1MON_THOUSANDS_SEP\s0" 4 .IX Item "MON_THOUSANDS_SEP" like \s-1THOUSANDS_SEP,\s0 but used for format_price .IP "\s-1MON_DECIMAL_POINT\s0" 4 .IX Item "MON_DECIMAL_POINT" like \s-1DECIMAL_POINT,\s0 but used for format_price .IP "\s-1INT_CURR_SYMBOL\s0" 4 .IX Item "INT_CURR_SYMBOL" character(s) denoting currency (see \fBformat_price()\fR) .IP "\s-1DECIMAL_DIGITS\s0" 4 .IX Item "DECIMAL_DIGITS" number of digits to the right of dec point (def 2) .IP "\s-1DECIMAL_FILL\s0" 4 .IX Item "DECIMAL_FILL" boolean; whether to add zeroes to fill out decimal .IP "\s-1NEG_FORMAT\s0" 4 .IX Item "NEG_FORMAT" format to display negative numbers (def \-x) .IP "\s-1KILO_SUFFIX\s0" 4 .IX Item "KILO_SUFFIX" suffix to add when format_bytes formats kilobytes .IP "\s-1MEGA_SUFFIX\s0" 4 .IX Item "MEGA_SUFFIX" suffix to add when format_bytes formats megabytes .IP "\s-1GIGA_SUFFIX\s0" 4 .IX Item "GIGA_SUFFIX" suffix to add when format_bytes formats gigabytes .SH "Using Template::Plugin::Number::Format" .IX Header "Using Template::Plugin::Number::Format" When you invoke: .PP .Vb 1 \& [% USE Number.Format(option = value) %] .Ve .PP the following filters are installed into the current Context: .IP "\fBround($precision)\fR" 4 .IX Item "round($precision)" Rounds the number to the specified precision. If \*(L"$precision\*(R" is omitted, the value of the \*(L"\s-1DECIMAL_DIGITS\*(R"\s0 parameter is used (default value 2). .IP "\fBformat_number($precision, \f(CB$trailing_zeros\fB)\fR" 4 .IX Item "format_number($precision, $trailing_zeros)" Formats a number by adding \*(L"\s-1THOUSANDS_SEP\*(R"\s0 between each set of 3 digits to the left of the decimal point, substituting \*(L"\s-1DECIMAL_POINT\*(R"\s0 for the decimal point, and rounding to the specified precision using \&\*(L"\fBround()\fR\*(R". Note that \*(L"$precision\*(R" is a maximum precision specifier; trailing zeroes will only appear in the output if \*(L"$trailing_zeroes\*(R" is provided, or the parameter \*(L"\s-1DECIMAL_FILL\*(R"\s0 is set, with a value that is true (not zero, undef, or the empty string). If \*(L"$precision\*(R" is omitted, the value of the \*(L"\s-1DECIMAL_DIGITS\*(R"\s0 parameter (default value of 2) is used. .IP "\fBformat_negative($picture)\fR" 4 .IX Item "format_negative($picture)" Formats a negative number. Picture should be a string that contains the letter \*(L"x\*(R" where the number should be inserted. For example, for standard negative numbers you might use \*(L"\-x\*(R", while for accounting purposes you might use \*(L"(x)\*(R". If the specified number begins with a \- character, that will be removed before formatting, but formatting will occur whether or not the number is negative. .IP "\fBformat_picture($picture)\fR" 4 .IX Item "format_picture($picture)" Returns a string based on \*(L"$picture\*(R" with the \*(L"#\*(R" characters replaced by digits from \*(L"$number\*(R". If the length of the integer part of \&\f(CW$number\fR is too large to fit, the \*(L"#\*(R" characters are replaced with asterisks (\*(L"*\*(R") instead. .IP "\fBformat_price($precision)\fR" 4 .IX Item "format_price($precision)" Returns a string containing \*(L"$number\*(R" formatted similarly to \&\*(L"\fBformat_number()\fR\*(R", except that the decimal portion may have trailing zeroes added to make it be exactly \*(L"$precision\*(R" characters long, and the currency string will be prefixed. .Sp If the \*(L"\s-1INT_CURR_SYMBOL\*(R"\s0 attribute of the object is the empty string, no currency will be added. .Sp If \*(L"$precision\*(R" is not provided, the default of 2 will be used. .IP "\fBformat_bytes($precision)\fR" 4 .IX Item "format_bytes($precision)" Returns a string containing \*(L"$number\*(R" formatted similarly to \&\*(L"\fBformat_number()\fR\*(R", except that if the number is over 1024, it will be divided by 1024 and the value of \s-1KILO_SUFFIX\s0 appended to the end; or if it is over 1048576 (1024*1024), it will be divided by 1048576 and \&\s-1MEGA_SUFFIX\s0 appended to the end. Negative values will result in an error. .Sp If \*(L"$precision\*(R" is not provided, the default of 2 will be used. .IP "\fBunformat_number\fR" 4 .IX Item "unformat_number" Converts a string as returned by \*(L"\fBformat_number()\fR\*(R", \*(L"\fBformat_price()\fR\*(R", or \*(L"\fBformat_picture()\fR\*(R", and returns the corresponding value as a numeric scalar. Returns \*(L"undef\*(R" if the number does not contain any digits. .SH "SEE ALSO" .IX Header "SEE ALSO" Template, Number::Format .SH "AUTHOR" .IX Header "AUTHOR" darren chamberlain