Format(3pm)
π Format(3pm) π
okay bestie, so this is a page from the User Contributed Perl Documentation and it's literally about the module Template::Plugin::Number::Format β yes that's the whole vibe, iykyk β¨
πΈ NAME πΈ
Template::Plugin::Number::Format β it's a plugin and a filter interface to Number::Format, and it ate, no cap π
β¨ SYNOPSIS β¨
[% USE Number.Format %]
[% num | format_number %]
look at that. two lines. iconic. periodt π
π¦ ABSTRACT π¦
Template::Plugin::Number::Format makes the number-munging grooviness of Number::Format available to your templates. You use it like a plugin, but plot twist β it installs filters into the current context. the way that it does both?? main character energy fr fr π
π DESCRIPTION π
So every single filter that Template::Plugin::Number::Format creates can be configured two ways: by constructor options, and by options you pass straight to individual filters. If you want all the juicy details, go read "METHODS" in Number::Format β that's where the lore lives, bestie π
π Constructor Parameters π
Your USE line takes these parameters, and they are all optional (no pressure, babe). They set the default behavior for the filters inside the current Context:
THOUSANDS_SEPβ the character that gets inserted between groups of 3 digits. grouping slay π«DECIMAL_POINTβ the character separating the integer part from the fractional part. the lil divider πMON_THOUSANDS_SEPβ same energy asTHOUSANDS_SEP, except it's the one used forformat_priceπΈMON_DECIMAL_POINTβ likeDECIMAL_POINT, but forformat_priceπ°MON_DECIMAL_POINT's cousin energy aside βINT_CURR_SYMBOLβ the character(s) that denote currency (peepformat_price()) πDECIMAL_DIGITSβ how many digits sit to the right of the decimal point (def 2) π’DECIMAL_FILLβ boolean; whether to add zeroes to fill out the decimal. yes/no vibes π«ΆNEG_FORMATβ the format for displaying negative numbers (def -x) πKILO_SUFFIXβ the suffix to add whenformat_bytesformats kilobytes πΈMEGA_SUFFIXβ the suffix to add whenformat_bytesformats megabytes πGIGA_SUFFIXβ the suffix to add whenformat_bytesformats gigabytes π₯
π§ Using Template::Plugin::Number::Format π§
When you invoke:
[% USE Number.Format(option = value) %]
the following filters get installed into the current Context. yes bestie, ALL of them π
round($precision)β Rounds the number to the specified precision. If$precisionis omitted, it uses the value of theDECIMAL_DIGITSparameter (default value 2). rounding is self care πformat_number($precision, $trailing_zeros)β Formats a number by addingTHOUSANDS_SEPbetween each set of 3 digits to the left of the decimal point, substitutingDECIMAL_POINTfor the decimal point, and rounding to the specified precision usinground(). Heads up though:$precisionis a maximum precision specifier, which means trailing zeroes will only show up in the output if$trailing_zeroesis provided, or if the parameterDECIMAL_FILLis set, with a value that is true (so not zero, not undef, not the empty string). And if$precisionis omitted, the value of theDECIMAL_DIGITSparameter (default value of 2) gets used. so many rules but we love her β¨format_negative($picture)β Formats a negative number. The picture should be a string containing the letterxexactly where the number should be inserted. For example, for standard negative numbers you might use-x, while for accounting purposes you might use(x). And if the specified number begins with a-character, that gets removed before formatting β but formatting will happen whether or not the number is negative. equal opportunity formatting fr fr πformat_picture($picture)β Returns a string based on$picturewith the#characters replaced by digits from$number. But if the integer part of$numberis too long to fit, those#characters get replaced with asterisks (*) instead. not the asterisks πformat_price($precision)β Returns a string containing$numberformatted similarly toformat_number(), except the decimal portion may have trailing zeroes added so it's exactly$precisioncharacters long, and the currency string gets prefixed. If theINT_CURR_SYMBOLattribute of the object is the empty string, then no currency gets added at all. And if$precisionisn't provided, the default of 2 is used. money money money πΈformat_bytes($precision)β Returns a string containing$numberformatted similarly toformat_number(), except: if the number is over 1024, it gets divided by 1024 and the value ofKILO_SUFFIXgets appended to the end; or if it's over 1048576 (1024*1024), it gets divided by 1048576 andMEGA_SUFFIXgets appended to the end. And bestie, listen β negative values will result in an error. do not do it. just don't π ββοΈ
If $precision is not provided, the default of 2 will be used.
unformat_numberβ Converts a string as returned byformat_number(),format_price(), orformat_picture(), and returns the corresponding value as a numeric scalar. And it returnsundefif the number doesn't contain any digits. the reverse uno card π
π SEE ALSO π
Template, Number::Format β go read those too, they're part of the friend group π«Ά
π AUTHOR π
darren chamberlain <darren@cpan.org> β the legend who wrote this π
and that's the whole page bestie, no notes π
so yeah, that was Format(3pm) from perl v5.34.0, dated 2022-06-17 β a true classic, we stan, ok bye love u πΈπ¦β¨
π¦ where this page comes from
- debian bookworm: libtemplate-plugin-number-format-perl 1.06-2 Β· GPL-2.0-only
- debian trixie: libtemplate-plugin-number-format-perl 1.06-2 Β· GPL-2.0-only
- ubuntu noble: libtemplate-plugin-number-format-perl 1.06-2 Β· GPL-2.0-only
- ubuntu resolute: libtemplate-plugin-number-format-perl 1.06-2 Β· GPL-2.0-only
- ubuntu stonking: libtemplate-plugin-number-format-perl 1.06-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms