Number-Format-1.79000755000765000024 015252747227 13371 5ustar00rjbsstaff000000000000TODO100644000765000024 44715252747227 14127 0ustar00rjbsstaff000000000000Number-Format-1.79The contents of this file have been moved to the SourceForge tracker: http://sourceforge.net/tracker/?group_id=175334&atid=872819 Please use SourceForge to track any bugs or new features from now on. The CPAN RT tracker can also be used: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Number-Format README100644000765000024 60515252747227 14313 0ustar00rjbsstaff000000000000Number-Format-1.79This archive contains the distribution Number-Format, version 1.79: Perl extension for formatting numbers This software is copyright (c) 1997 by William R. Ward . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.039. Changes100644000765000024 2670315252747227 14775 0ustar00rjbsstaff000000000000Number-Format-1.79Revision history for Number-Format 1.79 2026-09-17 07:27:17-04:00 America/New_York - document that format_bytes inherits the object's format_number settings, including decimal_fill for trailing zeroes (RT#125400) - document that format_price follows the locale's monetary sign rules and does not consult NEG_FORMAT (RT#124862) - documentation no longer claims that assigning to the exported :vars variables affects the functional interface; that has been broken since v1.60 in 2008 (RT#73717) - format_number keeps the sign on tiny negative numbers that fall back to scientific notation (RT#77643, thanks gsullivan) - format_picture no longer warns about an uninitialized value when neg_format has no prefix, like "x" (RT#148306) 1.78 2026-09-13 10:43:09-07:00 America/Los_Angeles - just making the previous release become a stable release 1.77 2026-02-22 18:23:39-05:00 America/New_York (TRIAL RELEASE) - Added support for terabytes. This feature was long omitted intentional for support with 32-bit perls. In 2026, we will assume that the user has a 64-bit perl and that on a 32-bit perl, they'll be used to coping. (And it's not the only use case, but… who has a terabyte of storage but a 32-bit perl, anyway?) - converted to Dist::Zilla for future maintenance by RJBS Changes for version 1.76 (May 25, 2023) ------------------------ - NOTE: This release was made by starting from the release archive on the CPAN and then applying a patch. It does not reflect the contents of the reference repository. Also, the file "bigfloat.t", referenced in the v1.75 changelog, was not in the previous release and is therefore not included here. - Patch to continue working on v5.38 upon its release (thanks, Karl Williamson) Changes for version 1.75 (June 25, 2015) ------------------------ - Export only necessary from POSIX (RT#99970, thanks Alexandr Ciornii) - Upgrade Makefile.PL (thanks Alexandr Ciornii) - Fix testing issue with missing locales (RT 97607, 97766, thanks to KHW) (thanks David Solimano) - Fix testing issue with bad Russian data on some platforms (RT 92666) (thanks David Solimano) - Add t/bigfloat.t (thanks Paul Miller / Alexandr Ciornii) Changes for version 1.74 (April 19, 2011) ------------------------ - Only Perl 5.10.0 and newer supported - Allow multi-character (e.g. " " for thousands_sep) (thanks Nick Patch; RT 65489) - Strip out illegal negative values returned by localeconv(), observed on Windows - see @IGNORE_NEGATIVE (thanks Adam Kennedy; RT 56802) - Manage warnings when undef is passed to methods (RT 48038) - Fix round() for Math::BigFloat objects (RT 62059) Changes for version 1.73 (September 25, 2009) ------------------------ - Fix locale.t for RUR/RUB distinction (thanks Kevin Phair; RT 46660/45833) - Skip locale.t for BSD (thanks Zak B. Elep; RT 48481/46367) - In _get_self add UNIVERSAL::isa check on ref (thanks Jordan Macdonald) Changes for version 1.72 (May 5, 2009) ------------------------ - Use Makefile.PL based on suggestion in RT 38020 - Add 'use strict' & 'use warnings' - Add MAX_INT constant for detecting overflows - Add helper sub _get_multipliers for getting kilo/mega/giga mult values - Add test in round() for overflow from large of a precision value (RT 40126) - Add .5 + 1e-14 to rounded value instead of .5000001 (RT 20298) - Fix undef $pic_prefix (RT 43029) - Add support for giga and base option in unformat_number (RT 40455) - Fix Russian locale issues, esp. in unformat_number (RT 40859) - Remove variables from error messages (XSS risk) and standardize errors - Remove requirement that decimal_point & thousands_sep be 1 char (for ru_RU) - Add Russian and unformat_number tests in locale.t - Add compare_numbers to test with an allowable error of 1e-10 in round.t Changes for version 1.71 (May 3, 2009) ------------------------ - Changes to tests t/format_price.t, t/locale.t, and t/round.t to fix cpan tester errors - No change to Format.pm itself Changes for version 1.70 (Feb 13, 2009) ------------------------ - Add support for IEC60027 (Ki, Mi, Gi prefixes) with mode option - Use hard coded hex values for base multiplier when base is 1024 - Use mon_ settings in format_number when called from format_price Changes for version 1.63 (Feb 10, 2009) ------------------------ - Minor tweak to format_bytes test for German locales Changes for version 1.62 (Feb 9, 2009) ------------------------ - Change format_bytes to fully specify all formatting options, not rely on locale at all as it was causing too many CPAN tester errors. Changes for version 1.61 (Dec 29, 2008) ------------------------ - Fix bugs in locale operations for format_price (thanks Moritz Onken) - Fix documentation in format_bytes (rt # 42036) - Enable warning when format_bytes called with numeric precision not hash Changes for version 1.60 (Jul 2, 2008) ------------------------ - Rewrite new() and format_price() to use mon_* POSIX Locale values - Add all missing POSIX Locale variables (Thanks to Kevin Ryde for help identifying the problem) Changes for version 1.52 (Sep 21, 2006) ------------------------ - Patch to t/format_price.t supplied by jonasbn addressing failling tests in 1.51, tests 2-6, the regex formatting the currency code did not take 0 occurrences of white space into account Patch: rt #21382 Resolves: rt #18964 (The same issue/patch was also reported by Cosimo Streppone, Randy W. Sims, J. R. Taisto) Changes for version 1.51 (Apr 26, 2006) ------------------------ - Patch to t/format_price.t supplied by Cosimo Streppone to allow it to work with non-US locales Changes for version 1.5 (Feb 14, 2005) ------------------------ - Require Perl 5.8 - was 5.003 before - Require POSIX.pm - was optional before - If C is set to the empty string, format_number will not insert any separators. - Replace "use vars" with "our" - Support scientific notation - skip formatting - Change format_bytes to support options (precision, unit, and base) instead of precision number Changes for version 1.45 (Aug 8, 2002) ------------------------ - No code change; only change is to test suite. - Replace all tab characters with spaces Changes for version 1.44 (Dec 11, 2001) ------------------------ - Add support for GIGA_SUFFIX. Can't do TERA because of integer overflow. - Detect decimal part correctly in Perl 5.6 and up Changes for version 1.43 (Dec 10, 2001) ------------------------ - Fix bug in format_price that caused an extra space to be inserted in some situations, and no space in others, between the currency string and the number. - Add support for gigabytes (formerly only kilo and mega) to format_bytes. (Thanks to Oeyvind Flaam ) Changes for version 1.42 (May 17, 2000) ------------------------ - Fixed bug in format_picture that was causing subsequent calls to return the previous result and the current one concatenated together. This is actually due to a bug in Perl, but a workaround was implemented. To avoid this problem in your own code, don't use code like this: "my VARIABLE = EXPRESSION if CONDITION" because if the CONDITION is false, the previous value of VARIABLE will still be there, even if it had gone out of scope! This bug was pointed out by Buddy Burden on 21 Mar 1999, Frank Tobin on 11 Jun 1999, Mark William Rostron on 12 Dec 1999, and Ben Tilly on 16 May 2000. Fix suggested by Buddy Burden, Mark William Rostron, and Ben Tilly. - Fixed bug in round() that was causing e.g. round(1.005, 2) to return 1 instead of 1.01. This is due to the vagaries of floating point arithmetic. I changed .5 to .5000001 in the rounding formula and added a check for this in the test suite. That seems to fix it but please let me know if you experience any weird results. This bug was reported by Kentaro Takatomi on 25 May 1999. - Fixed several points in the code where 'use of uninitialized value' warnings were generated. Reported by Frank Tobin on 11 Jun 1999. - In format_picture, replaced the use of $_ with a locally scoped variable ($char). This should reduce interference between this routine and any use of $_ by the calling program. Bug report and suggested fix by Mark William Rostron on 29 Dec 1999. Changes for version 1.41 (Nov 30, 1998) ------------------------ - Fix 'undefined value' warnings in format_picture - Fix bug in format_picture to show decimal point if and only if it is present in the picture string (bug reported by Michael Scoltock ) - Fix bug in format_price that would suppress currency symbol if no decimal digits (bug reported by Michael Scoltock ) Changes for version 1.40 (Nov 27, 1998) ------------------------ - Add new function format_bytes() to display '1K' for '1024', etc. (suggested by Curt Tilmes ) - Fix bugs in round() and format_picture() when dealing with negative numbers. NOTE: format_picture() now includes at least one extra space in its output for positive numbers. This may present a minor incompatibility issue in some obscure cases. - Minor documentation updates. Changes for version 1.30 (Oct 31, 1998) ------------------------ - Fix several major bugs, including the POSIX-not-required issue, as well as better support for negative values. - Add setting for default size of decimal area so you don't have to specify the number of digits if it's other than 2. - Add setting and function to display negative numbers in different formats. - Add setting to force trailing 0's in the decimal portion to fill out the number of digits required. - Fix problem where 0's inside format_picture()'s output were being replaced with spaces. - Add 0 before decimal point if number is between -1 and 1. - Fix errors with supposedly-optional POSIX - From: Yair Lenga Suggested adding controls to pad out result of format_number with zeroes as well as the ability to present negative numbers with parentheses. Provided a patch which was useful in constructing a solution. - Add test for defined() from patch by IMAZU Hideyo - From: "Joseph Norton" Bugs in format_number(): processed negative numbers incorrectly, and lacked the zero before the decimal point if number is between 0 and 1. Changes for version 1.20 (Aug 31, 1998) ------------------------ - Make POSIX no longer required (users on MicroSoft systems sometimes don't have it); uses US defaults if no POSIX.pm found. - Add new optional third argument to format_number() to add trailing zeroes. Changes for version 1.12 ------------------------ - Remove 'use of undefined value' warnings when used with perl -w Changes for version 1.10 (Nov 21, 1997) ------------------------ - Add Locale support to set the default values for $THOUSANDS_SEP, $DECIMAL_SEP, and $CURRENCY based on the user's locale. - Add object oriented interface. - NOTE: Some aspects of the API have changed. Please reread the documentation carefully if you used 1.0 previously!!! Initial version 1.00 -------------------- - Limited release beta version. LICENSE100644000765000024 4636715252747227 14517 0ustar00rjbsstaff000000000000Number-Format-1.79This software is copyright (c) 1997 by William R. Ward . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 1997 by William R. Ward . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Moe Ghoul, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 1997 by William R. Ward . This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End dist.ini100644000765000024 27515252747227 15102 0ustar00rjbsstaff000000000000Number-Format-1.79name = Number-Format author = William R. Ward license = Perl_5 copyright_holder = William R. Ward copyright_year = 1997 [@RJBS] perl-window = long-term META.yml100644000765000024 3040515252747227 14745 0ustar00rjbsstaff000000000000Number-Format-1.79--- abstract: 'Perl extension for formatting numbers' author: - 'William R. Ward ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0.96' strict: '0' configure_requires: ExtUtils::MakeMaker: '6.78' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.039, CPAN::Meta::Converter version 2.150013' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Number-Format requires: Carp: '0' Exporter: '0' POSIX: '0' base: '0' constant: '0' perl: '5.012' warnings: '0' resources: bugtracker: https://github.com/rjbs/Number-Format/issues homepage: https://github.com/rjbs/Number-Format repository: https://github.com/rjbs/Number-Format.git version: '1.79' x_Dist_Zilla: perl: version: '5.040001' plugins: - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@RJBS/Git::GatherDir' version: '2.052' - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@RJBS/CheckPrereqsIndexed' version: '0.022' - class: Dist::Zilla::Plugin::CheckExtraTests name: '@RJBS/CheckExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 0 check_all_prereqs: 0 modules: - Dist::Zilla::PluginBundle::RJBS phase: build run_under_travis: 0 skip: [] name: '@RJBS/RJBS-Outdated' version: '0.060' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 0 modules: [] phase: release run_under_travis: 0 skip: - Dist::Zilla::Plugin::RJBSMisc name: '@RJBS/CPAN-Outdated' version: '0.060' - class: Dist::Zilla::Plugin::PruneCruft name: '@RJBS/@Filter/PruneCruft' version: '6.039' - class: Dist::Zilla::Plugin::ManifestSkip name: '@RJBS/@Filter/ManifestSkip' version: '6.039' - class: Dist::Zilla::Plugin::MetaYAML name: '@RJBS/@Filter/MetaYAML' version: '6.039' - class: Dist::Zilla::Plugin::License name: '@RJBS/@Filter/License' version: '6.039' - class: Dist::Zilla::Plugin::Readme name: '@RJBS/@Filter/Readme' version: '6.039' - class: Dist::Zilla::Plugin::ExecDir name: '@RJBS/@Filter/ExecDir' version: '6.039' - class: Dist::Zilla::Plugin::ShareDir name: '@RJBS/@Filter/ShareDir' version: '6.039' - class: Dist::Zilla::Plugin::Manifest name: '@RJBS/@Filter/Manifest' version: '6.039' - class: Dist::Zilla::Plugin::TestRelease name: '@RJBS/@Filter/TestRelease' version: '6.039' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@RJBS/@Filter/ConfirmRelease' version: '6.039' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@RJBS/@Filter/UploadToCPAN' version: '6.039' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 9 name: '@RJBS/MakeMaker' version: '6.039' - class: Dist::Zilla::Plugin::AutoPrereqs name: '@RJBS/AutoPrereqs' version: '6.039' - class: Dist::Zilla::Plugin::Git::NextVersion config: Dist::Zilla::Plugin::Git::NextVersion: first_version: '0.001' version_by_branch: 1 version_regexp: (?^:^([0-9]+\.[0-9]+)$) Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/Git::NextVersion' version: '2.052' - class: Dist::Zilla::Plugin::PkgVersion name: '@RJBS/PkgVersion' version: '6.039' - class: Dist::Zilla::Plugin::MetaConfig name: '@RJBS/MetaConfig' version: '6.039' - class: Dist::Zilla::Plugin::MetaJSON name: '@RJBS/MetaJSON' version: '6.039' - class: Dist::Zilla::Plugin::NextRelease name: '@RJBS/NextRelease' version: '6.039' - class: Dist::Zilla::Plugin::Test::ChangesHasContent name: '@RJBS/Test::ChangesHasContent' version: '0.011' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@RJBS/PodSyntaxTests' version: '6.039' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@RJBS/Test::ReportPrereqs' version: '0.029' - class: Dist::Zilla::Plugin::Git::Remote::Check name: '@RJBS/Git::Remote::Check' version: 0.1.2 - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: 1 fail_on_warning: author fake_home: 0 filename: xt/author/00-compile.t module_finder: - ':InstallModules' needs_display: 0 phase: develop script_finder: - ':PerlExecFiles' skips: [] switch: [] name: '@RJBS/Test::Compile' version: '2.059' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@RJBS/TestMoreWithSubtests' version: '6.039' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugins: - '@RJBS' finder: - ':InstallModules' - ':PerlExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.020' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.020' - class: Pod::Weaver::Plugin::SingleEncoding name: '@RJBS/SingleEncoding' version: '4.020' - class: Pod::Weaver::Section::Name name: '@RJBS/Name' version: '4.020' - class: Pod::Weaver::Section::Version name: '@RJBS/Version' version: '4.020' - class: Pod::Weaver::Section::Region name: '@RJBS/Prelude' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Synopsis' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Description' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Overview' version: '4.020' - class: Pod::Weaver::Section::Generic name: '@RJBS/Stability' version: '4.020' - class: Pod::Weaver::Section::GenerateSection name: '@RJBS/PerlSupport' version: '4.020' - class: Pod::Weaver::Section::Collect name: Attributes version: '4.020' - class: Pod::Weaver::Section::Collect name: Methods version: '4.020' - class: Pod::Weaver::Section::Collect name: Functions version: '4.020' - class: Pod::Weaver::Section::Leftovers name: '@RJBS/Leftovers' version: '4.020' - class: Pod::Weaver::Section::Region name: '@RJBS/postlude' version: '4.020' - class: Pod::Weaver::Section::Authors name: '@RJBS/Authors' version: '4.020' - class: Pod::Weaver::Section::Contributors name: '@RJBS/Contributors' version: '0.009' - class: Pod::Weaver::Section::Legal name: '@RJBS/Legal' version: '4.020' - class: Pod::Weaver::Plugin::Transformer name: '@RJBS/List' version: '4.020' name: '@RJBS/PodWeaver' version: '4.010' - class: Dist::Zilla::Plugin::RJBSMisc name: '@RJBS/RJBSMisc' version: '5.036' - class: Dist::Zilla::Plugin::GithubMeta name: '@RJBS/GithubMeta' version: '0.58' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/@Git/Check' version: '2.052' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%V%n%n%c signoff: 0 Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Commit' version: '2.052' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '1.79' tag_format: '%v' tag_message: v%V Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Tag' version: '2.052' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - 'github :' remotes_must_exist: 0 Dist::Zilla::Role::Git::Repo: git_version: '2.50.1 (Apple Git-155)' repo_root: . name: '@RJBS/@Git/Push' version: '2.052' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: '2.50.1 (Apple Git-155)' include_authors: 0 include_releaser: 1 order_by: name paths: [] remove: ... name: '@RJBS/Git::Contributors' version: '0.039' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.039' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.039' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: '6.039' x_contributors: - 'Karl Williamson ' - 'Ricardo Signes ' x_generated_by_perl: v5.40.1 x_rjbs_perl_window: long-term x_serialization_backend: 'YAML::Tiny version 1.76' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' MANIFEST100644000765000024 67515252747227 14573 0ustar00rjbsstaff000000000000Number-Format-1.79# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.039 Changes LICENSE MANIFEST META.json META.yml Makefile.PL README TODO dist.ini lib/Number/Format.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/format_bytes.t t/format_negative.t t/format_number.t t/format_picture.t t/format_price.t t/locale.t t/object.t t/round.t t/unformat_number.t xt/author/00-compile.t xt/author/pod-syntax.t xt/release/changes_has_content.t t000755000765000024 015252747227 13555 5ustar00rjbsstaff000000000000Number-Format-1.79round.t100644000765000024 346215252747227 15236 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format', ':subs') } use constant PI => 4*atan2(1,1); ok(compare_numbers(round(0), 0), 'identity 0'); ok(compare_numbers(round(1), 1), 'identity 1'); ok(compare_numbers(round(-1), -1), 'identity -1'); ok(compare_numbers(round(PI,2), 3.14), 'pi prec=2'); ok(compare_numbers(round(PI,3), 3.142), 'pi prec=3'); ok(compare_numbers(round(PI,4), 3.1416), 'pi prec=4'); ok(compare_numbers(round(PI,5), 3.14159), 'pi prec=5'); ok(compare_numbers(round(PI,6), 3.141593), 'pi prec=6'); ok(compare_numbers(round(PI,7), 3.1415927), 'pi prec=7'); ok(compare_numbers(round(123456.512), 123456.51), 'precision=0' ); ok(compare_numbers(round(-1234567.509, 2), -1234567.51), 'negative thous' ); ok(compare_numbers(round(-12345678.5, 2), -12345678.5), 'negative tenths' ); ok(compare_numbers(round(-123456.78951, 4), -123456.7895), 'precision=4' ); ok(compare_numbers(round(123456.78951, -2), 123500), 'precision=-2' ); # Without the 1e-10 "epsilon" value in round(), the floating point # number math will result in 1 rather than 1.01 for this test. is(round(1.005, 2), 1.01, 'string-eq' ); # Compare numbers within an epsilon value to avoid false negative # results due to floating point math sub compare_numbers { my($p, $q) = @_; return abs($p - $q) < 1e-10; } { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is(round(undef), "0"); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::round at \Q$file\E line \d+[.]?\n}); } META.json100644000765000024 4646415252747227 15131 0ustar00rjbsstaff000000000000Number-Format-1.79{ "abstract" : "Perl extension for formatting numbers", "author" : [ "William R. Ward " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.039, CPAN::Meta::Converter version 2.150013", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Number-Format", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.78" } }, "develop" : { "requires" : { "Encode" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0.94", "Test::Pod" : "1.41", "strict" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "POSIX" : "0", "base" : "0", "constant" : "0", "perl" : "5.012", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::More" : "0.96", "strict" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/rjbs/Number-Format/issues" }, "homepage" : "https://github.com/rjbs/Number-Format", "repository" : { "type" : "git", "url" : "https://github.com/rjbs/Number-Format.git", "web" : "https://github.com/rjbs/Number-Format" } }, "version" : "1.79", "x_Dist_Zilla" : { "perl" : { "version" : "5.040001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@RJBS/Git::GatherDir", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@RJBS/CheckPrereqsIndexed", "version" : "0.022" }, { "class" : "Dist::Zilla::Plugin::CheckExtraTests", "name" : "@RJBS/CheckExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 0, "check_all_prereqs" : 0, "modules" : [ "Dist::Zilla::PluginBundle::RJBS" ], "phase" : "build", "run_under_travis" : 0, "skip" : [] } }, "name" : "@RJBS/RJBS-Outdated", "version" : "0.060" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 1, "check_all_prereqs" : 0, "modules" : [], "phase" : "release", "run_under_travis" : 0, "skip" : [ "Dist::Zilla::Plugin::RJBSMisc" ] } }, "name" : "@RJBS/CPAN-Outdated", "version" : "0.060" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@RJBS/@Filter/PruneCruft", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@RJBS/@Filter/ManifestSkip", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@RJBS/@Filter/MetaYAML", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@RJBS/@Filter/License", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@RJBS/@Filter/Readme", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@RJBS/@Filter/ExecDir", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@RJBS/@Filter/ShareDir", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@RJBS/@Filter/Manifest", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@RJBS/@Filter/TestRelease", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@RJBS/@Filter/ConfirmRelease", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@RJBS/@Filter/UploadToCPAN", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 9 } }, "name" : "@RJBS/MakeMaker", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@RJBS/AutoPrereqs", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "config" : { "Dist::Zilla::Plugin::Git::NextVersion" : { "first_version" : "0.001", "version_by_branch" : 1, "version_regexp" : "(?^:^([0-9]+\\.[0-9]+)$)" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/Git::NextVersion", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "@RJBS/PkgVersion", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@RJBS/MetaConfig", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@RJBS/MetaJSON", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@RJBS/NextRelease", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::Test::ChangesHasContent", "name" : "@RJBS/Test::ChangesHasContent", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@RJBS/PodSyntaxTests", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@RJBS/Test::ReportPrereqs", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::Git::Remote::Check", "name" : "@RJBS/Git::Remote::Check", "version" : "0.1.2" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : 1, "fail_on_warning" : "author", "fake_home" : 0, "filename" : "xt/author/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : 0, "phase" : "develop", "script_finder" : [ ":PerlExecFiles" ], "skips" : [], "switch" : [] } }, "name" : "@RJBS/Test::Compile", "version" : "2.059" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@RJBS/TestMoreWithSubtests", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugins" : [ "@RJBS" ], "finder" : [ ":InstallModules", ":PerlExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@RJBS/SingleEncoding", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@RJBS/Name", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@RJBS/Version", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/Prelude", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Synopsis", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Description", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Overview", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Stability", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::GenerateSection", "name" : "@RJBS/PerlSupport", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Attributes", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Methods", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Functions", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@RJBS/Leftovers", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/postlude", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@RJBS/Authors", "version" : "4.020" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "@RJBS/Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@RJBS/Legal", "version" : "4.020" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "@RJBS/List", "version" : "4.020" } ] } }, "name" : "@RJBS/PodWeaver", "version" : "4.010" }, { "class" : "Dist::Zilla::Plugin::RJBSMisc", "name" : "@RJBS/RJBSMisc", "version" : "5.036" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@RJBS/GithubMeta", "version" : "0.58" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/@Git/Check", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%V%n%n%c", "signoff" : 0 }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Commit", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "1.79", "tag_format" : "%v", "tag_message" : "v%V" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Tag", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "github :" ], "remotes_must_exist" : 0 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.50.1 (Apple Git-155)", "repo_root" : "." } }, "name" : "@RJBS/@Git/Push", "version" : "2.052" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.50.1 (Apple Git-155)", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [], "remove" : "..." } }, "name" : "@RJBS/Git::Contributors", "version" : "0.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.039" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.039" } }, "x_contributors" : [ "Karl Williamson ", "Ricardo Signes " ], "x_generated_by_perl" : "v5.40.1", "x_rjbs_perl_window" : "long-term", "x_serialization_backend" : "Cpanel::JSON::XS version 4.40", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } locale.t100644000765000024 537615252747227 15354 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More; use strict; use warnings; BEGIN { # Do not test when under OpenBSD; see # http://www.in-ulm.de/~mascheck/locale/ and # http://undeadly.org/cgi?action=article&sid=20030206041352 plan skip_all => 'OpenBSD C library lacks locale support' if $^O =~ /^(openbsd|dragonfly)$/; plan 'no_plan'; } BEGIN { use_ok('Number::Format') } BEGIN { use_ok('POSIX') } SKIP: { setlocale(&LC_ALL, 'de_DE') or setlocale(&LC_ALL, 'de_DE.utf8') or setlocale(&LC_ALL, 'de_DE.ISO8859-1') or skip("Unable to set de_DE locale", 1); my $german = Number::Format->new(); # On some sysetms (notably Mac OS X) the locale data is wrong for de_DE. # Force it to match what we would see on Linux so the test passes. $german->{n_cs_precedes} = $german->{p_cs_precedes} = '0'; $german->{n_sep_by_space} = $german->{p_sep_by_space} = '1'; $german->{thousands_sep} = '.'; $german->{decimal_point} = ','; my $curr = $german->{int_curr_symbol}; # may be EUR or DEM my $num = "123.456,79"; is($german->format_price(123456.789), "$num $curr", "euros"); is($german->unformat_number($num), 123456.79, "unformat German"); } SKIP: { setlocale(&LC_ALL, 'ru_RU') or setlocale(&LC_ALL, 'ru_RU.utf8') or setlocale(&LC_ALL, 'ru_RU.ISO8859-5') or skip("Unable to set ru_RU locale", 1); my $russian = Number::Format->new(); # On some sysetms (notably Cygwin) the locale data is wrong for ru_RU. # Force it to match what we would see on Linux so the test passes. $russian->{n_sep_by_space} = $russian->{p_sep_by_space} = '1'; my $sep = $russian->{mon_thousands_sep}; my $dec = $russian->{mon_decimal_point}; my $num = "123${sep}456${dec}79"; like($russian->format_price(123456.789), qr/^$num RU[RB] $/, "rubles"); is($russian->unformat_number("$num RUB "), 123456.79, "unformat rubles"); is($russian->unformat_number($num), 123456.79, "unformat Russian 1"); $num = "123${sep}456$russian->{decimal_point}79"; is($russian->unformat_number($num), 123456.79, "unformat Russian 2"); } my $num = "123,456.79"; SKIP: { setlocale(&LC_ALL, 'en_US') or setlocale(&LC_ALL, 'en_US.utf8') or setlocale(&LC_ALL, 'en_US.ISO8859-1') or skip("Unable to set en_US locale", 1); my $english = Number::Format->new(); is($english->format_price(123456.789), "USD $num", "USD"); is($english->unformat_number($num), 123456.79, "unformat English"); } setlocale(&LC_ALL, "C") or skip("Unable to set en_US locale", 1); my $c = Number::Format->new(); is($c->format_price(123456.789, 2, "currency_symbol"), "\$ $num", "Dollar sign"); is($c->unformat_number($num), 123456.79, "unformat C"); object.t100644000765000024 137215252747227 15353 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format') } my $deutsch = Number::Format->new(-thousands_sep => '.', -decimal_point => ','); isa_ok($deutsch, 'Number::Format', 'object'); is($deutsch->format_number(1234567.509, 2), '1.234.567,51', 'round'); is($deutsch->format_number(12345678.5, 2), '12.345.678,5', 'tousends'); is($deutsch->format_number(1.23456789, 6), '1,234568', 'big frac'); my $double_char = Number::Format->new( -thousands_sep => ' ', -decimal_point => ',', ); is( $double_char->format_number(12345678.5), "12 345 678,5", 'multi-char thousands separator' ); Makefile.PL100644000765000024 253515252747227 15431 0ustar00rjbsstaff000000000000Number-Format-1.79# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.039 use strict; use warnings; use 5.012; use ExtUtils::MakeMaker 6.78; my %WriteMakefileArgs = ( "ABSTRACT" => "Perl extension for formatting numbers", "AUTHOR" => "William R. Ward ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.78" }, "DISTNAME" => "Number-Format", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.012", "NAME" => "Number::Format", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "POSIX" => 0, "base" => 0, "constant" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::More" => "0.96", "strict" => 0 }, "VERSION" => "1.79", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "POSIX" => 0, "Test::More" => "0.96", "base" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); format_bytes.t100644000765000024 410215252747227 16575 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format', ':subs') } is(format_bytes(123.51), '123.51', 'no change'); is(format_bytes(1234567.509), '1.18M', 'mega'); is(format_bytes(1234.51, precision => 3), '1.206K', 'kilo'); is(format_bytes(123456789.1), '117.74M', 'bigger mega'); is(format_bytes(1234567890.1), '1.15G', 'giga'); is(format_bytes(12.95), '12.95', 'test 12.95'); is(format_bytes(12.95, precision => 0), '13', 'test 13 (precision 0)'); is(format_bytes(2048), '2K', 'test 2K'); is(format_bytes(9999999), '9.54M', 'test 9.54M'); is(format_bytes(9999999, precision => 1), '9.5M', 'test 9.5M, (precision 1)'); # Test for unit option is(format_bytes(1048576, unit => 'K'), '1,024K', 'test 1,024K, unit K'); # Tests for iec60027 mode is(format_bytes(123.51, mode => "iec"), '123.51', 'no change iec'); is(format_bytes(1234567.509, mode => "iec"), '1.18MiB', 'mebi'); is(format_bytes(1234.51, mode => "iec", precision => 3), '1.206KiB', 'kibi'); is(format_bytes(123456789.1, mode => "iec"), '117.74MiB', 'bigger mebi'); is(format_bytes(1234567890.1, mode => "iec"), '1.15GiB', 'gibi'); is(format_bytes(1048576, mode => "iec", unit => 'K'), '1,024KiB', 'iec unit'); # Tests for >32-bit values is(format_bytes(1_234_567_890_123, mode => "trad"), '1.12T', 'tera'); is(format_bytes(1_234_567_890_123, mode => "iec"), '1.12TiB', 'tebi'); is(format_bytes(1_234_567_890_123, base => 1000), '1.23T', 'teradecimal'); is(format_bytes( 123_456_789_012, mode => "iec", unit => 'T'), '0.11TiB', 'sub-tebi'); { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is(format_bytes(undef), "0"); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::format_bytes at \Q$file\E line \d+[.]?\n}); } format_price.t100644000765000024 1552715252747227 16606 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format') } my $usd = Number::Format->new( -int_curr_symbol => 'USD', -currency_symbol => '$', -decimal_point => '.', -frac_digits => 2, -int_frac_digits => 2, -n_cs_precedes => 1, -n_sep_by_space => 1, -n_sign_posn => 1, -negative_sign => '-', -p_cs_precedes => 1, -p_sep_by_space => 1, -p_sign_posn => 1, -positive_sign => '', -thousands_sep => ',', -mon_thousands_sep => ',', -decimal_fill => 1, -decimal_digits => 2, -mon_decimal_point => '.', ); is($usd->format_price(123456.51), 'USD 123,456.51', 'thou'); is($usd->format_price(1234567.509), 'USD 1,234,567.51', 'mill'); is($usd->format_price(1234.51, 3), 'USD 1,234.510', 'three dec'); is($usd->format_price(123456789.1), 'USD 123,456,789.10', 'zero in dec'); is($usd->format_price(100, '0'), 'USD 100', 'no dec'); $usd->{p_cs_precedes} = 1; $usd->{p_sep_by_space} = 0; $usd->{n_cs_precedes} = 1; $usd->{n_sep_by_space} = 0; $usd->{p_sign_posn} = 1; $usd->{n_sign_posn} = 1; is($usd->format_price(19.95, undef, 'currency_symbol'), '$19.95', 'domestic'); $usd->{int_frac_digits} = 4; $usd->{frac_digits} = 3; is($usd->format_price(19.95, undef, 'currency_symbol'), '$19.950', 'frac_digits'); is($usd->format_price(19.95), 'USD19.9500', 'int frac digits'); $usd->{n_sign_posn} = 0; is($usd->format_price(-9.95), '(USD9.9500)', 'n_sign_posn=0'); $usd->{n_sign_posn} = 1; is($usd->format_price(-9.95), '-USD9.9500', 'n_sign_posn=1'); $usd->{n_sign_posn} = 2; is($usd->format_price(-9.95), 'USD9.9500-', 'n_sign_posn=2'); $usd->{n_sign_posn} = 3; is($usd->format_price(-9.95), '-USD9.9500', 'n_sign_posn=3'); $usd->{n_sign_posn} = 4; is($usd->format_price(-9.95), 'USD-9.9500', 'n_sign_posn=4'); $usd->{n_cs_precedes} = 1; $usd->{n_sign_posn} = 3; $usd->{n_sep_by_space} = 0; is($usd->format_price(-9.95), '-USD9.9500', 'cs_precedes=1,sep_by_space=0'); $usd->{n_sep_by_space} = 1; is($usd->format_price(-9.95), '-USD 9.9500', 'cs_precedes=1,sep_by_space=1'); $usd->{n_sep_by_space} = 2; is($usd->format_price(-9.95), '- USD9.9500', 'cs_precedes=1,sep_by_space=2'); $usd->{n_cs_precedes} = 0; $usd->{n_sign_posn} = 3; $usd->{n_sep_by_space} = 0; is($usd->format_price(-9.95), '9.9500-USD', 'cs_precedes=0,sep_by_space=0'); $usd->{n_sep_by_space} = 1; is($usd->format_price(-9.95), '9.9500 -USD', 'cs_precedes=0,sep_by_space=1'); $usd->{n_sep_by_space} = 2; is($usd->format_price(-9.95), '9.9500- USD', 'cs_precedes=0,sep_by_space=2'); my %results = ('sep=0 posn=0 prec=0' => '(9.9500USD)', 'sep=0 posn=0 prec=1' => '(USD9.9500)', 'sep=0 posn=1 prec=0' => '-9.9500USD', 'sep=0 posn=1 prec=1' => '-USD9.9500', 'sep=0 posn=2 prec=0' => '9.9500USD-', 'sep=0 posn=2 prec=1' => 'USD9.9500-', 'sep=0 posn=3 prec=0' => '9.9500-USD', 'sep=0 posn=3 prec=1' => '-USD9.9500', 'sep=0 posn=4 prec=0' => '9.9500USD-', 'sep=0 posn=4 prec=1' => 'USD-9.9500', 'sep=1 posn=0 prec=0' => '(9.9500 USD)', 'sep=1 posn=0 prec=1' => '(USD 9.9500)', 'sep=1 posn=1 prec=0' => '-9.9500 USD', 'sep=1 posn=1 prec=1' => '-USD 9.9500', 'sep=1 posn=2 prec=0' => '9.9500 USD-', 'sep=1 posn=2 prec=1' => 'USD 9.9500-', 'sep=1 posn=3 prec=0' => '9.9500 -USD', 'sep=1 posn=3 prec=1' => '-USD 9.9500', 'sep=1 posn=4 prec=0' => '9.9500 USD-', 'sep=1 posn=4 prec=1' => 'USD- 9.9500', 'sep=2 posn=0 prec=0' => '(9.9500USD)', 'sep=2 posn=0 prec=1' => '(USD9.9500)', 'sep=2 posn=1 prec=0' => '- 9.9500USD', 'sep=2 posn=1 prec=1' => '- USD9.9500', 'sep=2 posn=2 prec=0' => '9.9500USD -', 'sep=2 posn=2 prec=1' => 'USD9.9500 -', 'sep=2 posn=3 prec=0' => '9.9500- USD', 'sep=2 posn=3 prec=1' => '- USD9.9500', 'sep=2 posn=4 prec=0' => '9.9500USD -', 'sep=2 posn=4 prec=1' => 'USD -9.9500' ); foreach my $sep (0..2) { foreach my $posn (0..4) { foreach my $prec (0..1) { my $key = "sep=$sep posn=$posn prec=$prec"; my $want = $results{$key}; $usd->{n_cs_precedes} = $prec; $usd->{n_sign_posn} = $posn; $usd->{n_sep_by_space} = $sep; is($usd->format_price(-9.95), $want, "$key -> $want"); } } } my %prices = ( 1234 => "EUR 1.234,00", 56 => "EUR 56,00", 75.2345 => "EUR 75,23", 12578.5 => "EUR 12.578,50" ); my $nf = Number::Format->new( -int_curr_symbol => 'EUR', -currency_symbol => '$', -decimal_point => ',', -frac_digits => 2, -int_frac_digits => 2, -n_cs_precedes => 1, -n_sep_by_space => 1, -n_sign_posn => 1, -negative_sign => '-', -p_cs_precedes => 1, -p_sep_by_space => 1, -p_sign_posn => 1, -positive_sign => '', -thousands_sep => '.', -mon_thousands_sep => '.', -decimal_fill => 1, -decimal_digits => 2, -mon_decimal_point => ',', ); for my $price ( sort keys %prices ) { my $want = $prices{$price}; is($nf->format_price($price, 2), $want, "$price -> $want"); } { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is($nf->format_price(undef), "EUR 0,00"); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::format_price at \Q$file\E line \d+[.]?\n}); } format_number.t100644000765000024 345215252747227 16746 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format', ':subs') } is(format_number(123456.51), '123,456.51', 'thousands'); is(format_number(1234567.509, 2), '1,234,567.51', 'rounding'); is(format_number(12345678.5, 2), '12,345,678.5', 'one digit'); is(format_number(123456789.51, 2), '123,456,789.51', 'hundreds of millions'); is(format_number(1.23456789, 6), '1.234568', 'six digit rounding'); is(format_number('1.2300', 7, 1), '1.2300000', 'extra zeroes'); is(format_number(.23, 7, 1), '0.2300000', 'leading zero'); is(format_number(-100, 7, 1), '-100.0000000', 'negative with zeros'); is(format_number(-1e-5, 5), '-1e-05', 'negative scientific'); # # https://rt.cpan.org/Ticket/Display.html?id=40126 # The test should fail because 20 digits is too big to correctly store # in a scalar variable without using Math::BigFloat. # eval { format_number(97, 20) }; like($@, qr/^\Qround() overflow. Try smaller precision or use Math::BigFloat/, "round overflow"); # # https://rt.cpan.org/Ticket/Display.html?id=48038 # Test with warnings enabled - expect a warning when called with undef # { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is(format_number(undef), "0"); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::format_number at \Q$file\E line \d+[.]?\n}); } # # https://rt.cpan.org/Ticket/Display.html?id=48038 # Test again with warnings disabled to see if we do NOT get the warning # { no warnings "uninitialized"; my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is(format_number(undef), "0"); my $file = __FILE__; is("@warnings", ""); } format_picture.t100644000765000024 350015252747227 17123 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format') } my $pic = 'US$##,###,###.##'; my $x = Number::Format->new; $x->{neg_format} = '-x'; is($x->format_picture(123456.512, $pic), 'US$ 123,456.51', 'thou'); is($x->format_picture(-1234567.509, $pic), 'US$ -1,234,567.51', 'neg'); is($x->format_picture(12345678.5, $pic), 'US$ 12,345,678.50', 'zero'); is($x->format_picture(123456789.51, $pic), 'US$ **,***,***.**', 'pos over'); is($x->format_picture(-123456789.51, $pic), 'US$-**,***,***.**', 'neg over'); is($x->format_picture(1023012.34, $pic), 'US$ 1,023,012.34', 'million'); is($x->format_picture(120450.789012, $pic), 'US$ 120,450.79', 'pos rnd'); is($x->format_picture(-120450.789012, $pic),'US$ -120,450.79', 'neg rnd'); $x->{neg_format} = '(x)'; is($x->format_picture(120450.789012, $pic), 'US$ 120,450.79 ', 'pos paren'); is($x->format_picture(-120450.789012, $pic),'US$ (120,450.79)', 'neg paren'); $pic = '#'; is($x->format_picture(1, $pic), ' 1 ', 'one digit 1'); is($x->format_picture(2, $pic), ' 2 ', 'one digit 2'); # RT#148306: a neg_format with no prefix must not warn { my @warnings; local $SIG{__WARN__} = sub { push @warnings, @_ }; my $bare = Number::Format->new(neg_format => 'x'); is($bare->format_picture(1234567, '###,###,###'), ' 1,234,567', 'bare pos'); is($bare->format_picture(-1234567, '###,###,###'), ' 1,234,567', 'bare neg'); is_deeply(\@warnings, [], 'no warnings with neg_format "x"'); } { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is($x->format_picture(undef, $pic), " 0 "); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::format_picture at \Q$file\E line \d+[.]?\n}); } format_negative.t100644000765000024 171115252747227 17254 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format') } my $x = Number::Format->new; $x->{neg_format}='-x'; is($x->format_negative(123456.51), '-123456.51', 'negative'); is($x->format_number(-.509), '-0.51', 'neg round'); $x->{decimal_digits}=5; is($x->format_negative(.5555), '-0.5555', 'neg no fill'); $x->{decimal_fill}=1; is($x->format_number(-.5555), '-0.55550', 'neg fill'); $x->{neg_format}='(x)'; is($x->format_number(-1), '(1.00000)', 'neg paren'); is($x->format_number(-.5), '(0.50000)', 'neg paren zero'); { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is($x->format_negative(undef), "(0)"); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::format_negative at \Q$file\E line \d+[.]?\n}); } unformat_number.t100644000765000024 405115252747227 17305 0ustar00rjbsstaff000000000000Number-Format-1.79/t# -*- CPerl -*- use Test::More qw(no_plan); use strict; use warnings; use POSIX; setlocale(&LC_ALL, 'C'); BEGIN { use_ok('Number::Format', ':subs') } cmp_ok(unformat_number('123,456.51'), '==', 123456.51, 'num'); cmp_ok(unformat_number('US$ 12,345,678.51'), '==', 12345678.51, 'curr'); ok(! defined unformat_number('US$###,###,###.##'), 'overflow picture'); cmp_ok(unformat_number('-123,456,789.51'), '==', -123456789.51,'neg'); cmp_ok(unformat_number('1.5K'), '==', 1536, 'kilo'); cmp_ok(unformat_number('1.3M'), '==', 1363148.8, 'mega'); my $x = Number::Format->new; $x->{neg_format} = '(x)'; cmp_ok($x->unformat_number('(123,456,789.51)'), '==', -123456789.51,'neg paren'); cmp_ok(unformat_number('(123,456,789.51)'), '==', 123456789.51,'neg default'); cmp_ok(unformat_number("4K", base => 1024), '==', 4096, '4x1024'); cmp_ok(unformat_number("4K", base => 1000), '==', 4000, '4x1000'); cmp_ok(unformat_number("4KiB", base => 1024), '==', 4096, '4x1024 KiB'); cmp_ok(unformat_number("4KiB", base => 1000), '==', 4000, '4x1000 KiB'); cmp_ok(unformat_number("4G"), '==', 4294967296, '4G'); cmp_ok(unformat_number("4T"), '==', 4 * 2**40, '4T'); cmp_ok(unformat_number("4TiB", base => 1024), '==', 4 * 2**40, '4x1024 TiB'); cmp_ok(unformat_number("4TiB", base => 1000), '==', 4 * 1e12, '4x1000 TiB'); cmp_ok(unformat_number("4G", base => 1), '==', 4, 'base 1'); eval { unformat_number("4G", base => 1000000) }; like($@, qr/^\Qbase overflow/, "base overflow"); eval { unformat_number("4G", base => 0) }; like($@, qr/^\Qbase must be a positive integer/, "base 0"); eval { unformat_number("4G", base => .5) }; like($@, qr/^\Qbase must be a positive integer/, "base .5"); eval { unformat_number("4G", base => -1) }; like($@, qr/^\Qbase must be a positive integer/, "base neg"); { my @warnings; local $SIG{__WARN__} = sub { @warnings = @_ }; is(unformat_number(undef), undef); my $file = __FILE__; like("@warnings", qr{Use of uninitialized value in call to Number::Format::unformat_number at \Q$file\E line \d+[.]?\n}); } Number000755000765000024 015252747227 15310 5ustar00rjbsstaff000000000000Number-Format-1.79/libFormat.pm100644000765000024 21173415252747227 17306 0ustar00rjbsstaff000000000000Number-Format-1.79/lib/Numberpackage Number::Format 1.79; # ABSTRACT: Perl extension for formatting numbers use v5.12.0; use warnings; #pod =head1 SYNOPSIS #pod #pod use Number::Format; #pod my $x = Number::Format->new(%args); #pod $formatted = $x->round($number, $precision); #pod $formatted = $x->format_number($number, $precision, $trailing_zeroes); #pod $formatted = $x->format_negative($number, $picture); #pod $formatted = $x->format_picture($number, $picture); #pod $formatted = $x->format_price($number, $precision, $symbol); #pod $formatted = $x->format_bytes($number, $precision); #pod $number = $x->unformat_number($formatted); #pod #pod use Number::Format qw(:subs); #pod $formatted = round($number, $precision); #pod $formatted = format_number($number, $precision, $trailing_zeroes); #pod $formatted = format_negative($number, $picture); #pod $formatted = format_picture($number, $picture); #pod $formatted = format_price($number, $precision, $symbol); #pod $formatted = format_bytes($number, $precision); #pod $number = unformat_number($formatted); #pod #pod =head1 DESCRIPTION #pod #pod These functions provide an easy means of formatting numbers in a #pod manner suitable for displaying to the user. #pod #pod There are two ways to use this package. One is to declare an object #pod of type Number::Format, which you can think of as a formatting engine. #pod The various functions defined here are provided as object methods. #pod The constructor C can be used to set the parameters of the #pod formatting engine. Valid parameters are: #pod #pod THOUSANDS_SEP - character inserted between groups of 3 digits #pod DECIMAL_POINT - character separating integer and fractional parts #pod MON_THOUSANDS_SEP - like THOUSANDS_SEP, but used for format_price #pod MON_DECIMAL_POINT - like DECIMAL_POINT, but used for format_price #pod INT_CURR_SYMBOL - character(s) denoting currency (see format_price()) #pod DECIMAL_DIGITS - number of digits to the right of dec point (def 2) #pod DECIMAL_FILL - boolean; whether to add zeroes to fill out decimal #pod NEG_FORMAT - format to display negative numbers (def ``-x'') #pod KILO_SUFFIX - suffix to add when format_bytes formats kilobytes (trad) #pod MEGA_SUFFIX - " " " " " " megabytes (trad) #pod GIGA_SUFFIX - " " " " " " gigabytes (trad) #pod TERA_SUFFIX - " " " " " " terabytes (trad) #pod KIBI_SUFFIX - suffix to add when format_bytes formats kibibytes (iec) #pod MEBI_SUFFIX - " " " " " " mebibytes (iec) #pod GIBI_SUFFIX - " " " " " " gibibytes (iec) #pod TEBI_SUFFIX - " " " " " " tebibytes (iec) #pod #pod They may be specified in upper or lower case, with or without a #pod leading hyphen ( - ). #pod #pod If C is set to the empty string, format_number will not #pod insert any separators. #pod #pod The defaults for C, C, #pod C, C, and C #pod come from the POSIX locale information (see L). If your #pod POSIX locale does not provide C and/or #pod C fields, then the C and/or #pod C values are used for those parameters. Formerly, #pod POSIX was optional but this caused problems in some cases, so it is #pod now required. If this causes you hardship, please contact the author #pod of this package at (remove "SPAM" to get correct #pod email address) for help. #pod #pod If any of the above parameters are not specified when you invoke #pod C, the values are taken from the current locale, and failing #pod that from these built-in defaults: #pod #pod THOUSANDS_SEP = ',' #pod DECIMAL_POINT = '.' #pod MON_THOUSANDS_SEP = ',' #pod MON_DECIMAL_POINT = '.' #pod INT_CURR_SYMBOL = 'USD' #pod DECIMAL_DIGITS = 2 #pod DECIMAL_FILL = 0 #pod NEG_FORMAT = '-x' #pod KILO_SUFFIX = 'K' #pod MEGA_SUFFIX = 'M' #pod GIGA_SUFFIX = 'G' #pod TERA_SUFFIX = 'T' #pod KIBI_SUFFIX = 'KiB' #pod MEBI_SUFFIX = 'MiB' #pod GIBI_SUFFIX = 'GiB' #pod TEBI_SUFFIX = 'TiB' #pod #pod Note however that when you first call one of the functions in this #pod module I using the object-oriented interface, further setting #pod of those global variables will have no effect on non-OO calls. It is #pod recommended that you use the object-oriented interface instead for #pod fewer headaches and a cleaner design. #pod #pod The C and C values are not set by the #pod Locale system, but are definable by the user. They affect the output #pod of C. Setting C is like giving that #pod value as the C<$precision> argument to that function. Setting #pod C to a true value causes C to append #pod zeroes to the right of the decimal digits until the length is the #pod specified number of digits. #pod #pod C is only used by C and is a string #pod containing the letter 'x', where that letter will be replaced by a #pod positive representation of the number being passed to that function. #pod C and C utilize this feature by #pod calling C if the number was less than 0. #pod #pod C, C, C, and C are #pod used by C when the value is over 1024, 1024**2, 1024**3, #pod or 1024**4, respectively. The default values are "K", "M", "G", and #pod "T". These apply in the default "traditional" mode only. #pod #pod C, C, C, and C are #pod used by C when the value is over 1024, 1024**2, #pod 1024**3, or 1024**4, respectively. The default values are "KiB", "MiB", #pod "GiB", "TiB". These apply in the "iso60027" mode only. #pod #pod The only restrictions on C and C are that #pod they must not be digits and must not be identical. There are no #pod restrictions on C. #pod #pod For example, a German user might include this in their code: #pod #pod use Number::Format; #pod my $de = Number::Format->new(-thousands_sep => '.', #pod -decimal_point => ',', #pod -int_curr_symbol => 'DEM'); #pod my $formatted = $de->format_number($number); #pod #pod Or, if you prefer not to use the object oriented interface, you can call #pod the functions directly: #pod #pod use Number::Format qw(:subs); #pod my $formatted = format_number($number); #pod #pod In that case the parameters come from the current locale and the #pod built-in defaults, and there is no way to override them. If you need #pod non-default parameters, use the object oriented interface. #pod #pod =head1 EXPORTS #pod #pod Nothing is exported by default. To export functions, name them on the #pod import list of the C statement, or use the tag #pod C<:subs> to export all of them. #pod #pod The tag C<:vars> (and the variables half of C<:all>) still exists for #pod compatibility, but it no longer has any useful purpose. It exports a #pod set of package variables that were once the way to configure the #pod functional interface; assigning to them has had no effect since version #pod 1.60 in 2008. Use C instead. #pod #pod =cut ###--------------------------------------------------------------------- use Exporter; use Carp; use POSIX qw(localeconv); use base qw(Exporter); our @EXPORT_SUBS = qw( format_number format_negative format_picture format_price format_bytes round unformat_number ); our @EXPORT_LC_NUMERIC = qw( $DECIMAL_POINT $THOUSANDS_SEP $GROUPING ); our @EXPORT_LC_MONETARY = qw( $INT_CURR_SYMBOL $CURRENCY_SYMBOL $MON_DECIMAL_POINT $MON_THOUSANDS_SEP $MON_GROUPING $POSITIVE_SIGN $NEGATIVE_SIGN $INT_FRAC_DIGITS $FRAC_DIGITS $P_CS_PRECEDES $P_SEP_BY_SPACE $N_CS_PRECEDES $N_SEP_BY_SPACE $P_SIGN_POSN $N_SIGN_POSN ); our @EXPORT_OTHER = qw( $DECIMAL_DIGITS $DECIMAL_FILL $NEG_FORMAT $KILO_SUFFIX $MEGA_SUFFIX $GIGA_SUFFIX $TERA_SUFFIX $KIBI_SUFFIX $MEBI_SUFFIX $GIBI_SUFFIX $TEBI_SUFFIX); our @EXPORT_VARS = ( @EXPORT_LC_NUMERIC, @EXPORT_LC_MONETARY, @EXPORT_OTHER ); our @EXPORT_ALL = ( @EXPORT_SUBS, @EXPORT_VARS ); our @EXPORT_OK = ( @EXPORT_ALL ); our %EXPORT_TAGS = ( subs => \@EXPORT_SUBS, vars => \@EXPORT_VARS, lc_numeric_vars => \@EXPORT_LC_NUMERIC, lc_monetary_vars => \@EXPORT_LC_MONETARY, other_vars => \@EXPORT_OTHER, all => \@EXPORT_ALL ); # Refer to http://www.opengroup.org/onlinepubs/007908775/xbd/locale.html # for more details about the POSIX variables # Locale variables provided by POSIX for numbers (LC_NUMERIC) our $DECIMAL_POINT = '.'; # decimal point symbol for numbers our $THOUSANDS_SEP = ','; # thousands separator for numbers our $GROUPING = undef;# grouping rules for thousands (UNSUPPORTED) # Locale variables provided by POSIX for currency (LC_MONETARY) our $INT_CURR_SYMBOL = 'USD';# intl currency symbol our $CURRENCY_SYMBOL = '$'; # domestic currency symbol our $MON_DECIMAL_POINT = '.'; # decimal point symbol for monetary values our $MON_THOUSANDS_SEP = ','; # thousands separator for monetary values our $MON_GROUPING = undef;# like 'grouping' for monetary (UNSUPPORTED) our $POSITIVE_SIGN = ''; # string to add for non-negative monetary our $NEGATIVE_SIGN = '-'; # string to add for negative monetary our $INT_FRAC_DIGITS = 2; # digits to right of decimal for intl currency our $FRAC_DIGITS = 2; # digits to right of decimal for currency our $P_CS_PRECEDES = 1; # curr sym precedes(1) or follows(0) positive our $P_SEP_BY_SPACE = 1; # add space to positive; 0, 1, or 2 our $N_CS_PRECEDES = 1; # curr sym precedes(1) or follows(0) negative our $N_SEP_BY_SPACE = 1; # add space to negative; 0, 1, or 2 our $P_SIGN_POSN = 1; # sign rules for positive: 0-4 our $N_SIGN_POSN = 1; # sign rules for negative: 0-4 # The following are specific to Number::Format our $DECIMAL_DIGITS = 2; our $DECIMAL_FILL = 0; our $NEG_FORMAT = '-x'; our $KILO_SUFFIX = 'K'; our $MEGA_SUFFIX = 'M'; our $GIGA_SUFFIX = 'G'; our $TERA_SUFFIX = 'T'; our $KIBI_SUFFIX = 'KiB'; our $MEBI_SUFFIX = 'MiB'; our $GIBI_SUFFIX = 'GiB'; our $TEBI_SUFFIX = 'TiB'; our $DEFAULT_LOCALE = { ( # LC_NUMERIC decimal_point => $DECIMAL_POINT, thousands_sep => $THOUSANDS_SEP, grouping => $GROUPING, # LC_MONETARY int_curr_symbol => $INT_CURR_SYMBOL, currency_symbol => $CURRENCY_SYMBOL, mon_decimal_point => $MON_DECIMAL_POINT, mon_thousands_sep => $MON_THOUSANDS_SEP, mon_grouping => $MON_GROUPING, positive_sign => $POSITIVE_SIGN, negative_sign => $NEGATIVE_SIGN, int_frac_digits => $INT_FRAC_DIGITS, frac_digits => $FRAC_DIGITS, p_cs_precedes => $P_CS_PRECEDES, p_sep_by_space => $P_SEP_BY_SPACE, n_cs_precedes => $N_CS_PRECEDES, n_sep_by_space => $N_SEP_BY_SPACE, p_sign_posn => $P_SIGN_POSN, n_sign_posn => $N_SIGN_POSN, # The following are specific to Number::Format decimal_digits => $DECIMAL_DIGITS, decimal_fill => $DECIMAL_FILL, neg_format => $NEG_FORMAT, kilo_suffix => $KILO_SUFFIX, mega_suffix => $MEGA_SUFFIX, giga_suffix => $GIGA_SUFFIX, tera_suffix => $TERA_SUFFIX, kibi_suffix => $KIBI_SUFFIX, mebi_suffix => $MEBI_SUFFIX, gibi_suffix => $GIBI_SUFFIX, tebi_suffix => $TEBI_SUFFIX, ) }; # # POSIX::localeconv() returns -1 for numeric values that are not applicable to # the current locale. This module ignores them. @IGNORE_NEGATIVE lists the # ones that this module otherwise handles (there are some fields that this # module always ignores, so don't need to be in the list). (Prior to v5.37.7, # only the Windows version of POSIX::localeconv() returned -1; other versions # simply didn't return any values at all for not-applicable fields. But the # end result is the same regardless of version.) # our @IGNORE_NEGATIVE = qw( frac_digits int_frac_digits n_cs_precedes n_sep_by_space n_sign_posn p_xs_precedes p_sep_by_space p_sign_posn ); # # Largest integer a 32-bit Perl can handle is based on the mantissa # size of a double float, which is up to 53 bits. While we may be # able to support larger values on 64-bit systems, some Perl integer # operations on 64-bit integer systems still use the 53-bit-mantissa # double floats. To be safe, we cap at 2**53; use Math::BigFloat # instead for larger numbers. # use constant MAX_INT => 2**53; ###--------------------------------------------------------------------- # INTERNAL FUNCTIONS # These functions (with names beginning with '_' are for internal use # only. There is no guarantee that they will remain the same from one # version to the next! ##---------------------------------------------------------------------- # _get_self creates an instance of Number::Format with the default # values for the configuration parameters, if the first element of # @_ is not already an object. my $DefaultObject; sub _get_self { # Not calling $_[0]->isa because that may result in unblessed # reference error unless (ref $_[0] && UNIVERSAL::isa($_[0], "Number::Format")) { $DefaultObject ||= Number::Format->new(); unshift (@_, $DefaultObject); } @_; } ##---------------------------------------------------------------------- # _check_seps is used to validate that the thousands_sep, # decimal_point, mon_thousands_sep and mon_decimal_point variables # have acceptable values. For internal use only. sub _check_seps { my ($self) = @_; croak "Not an object" unless ref $self; foreach my $prefix ("", "mon_") { croak "${prefix}thousands_sep is undefined" unless defined $self->{"${prefix}thousands_sep"}; croak "${prefix}thousands_sep may not be numeric" if $self->{"${prefix}thousands_sep"} =~ /\d/; croak "${prefix}decimal_point may not be numeric" if $self->{"${prefix}decimal_point"} =~ /\d/; croak("${prefix}thousands_sep and ". "${prefix}decimal_point may not be equal") if $self->{"${prefix}decimal_point"} eq $self->{"${prefix}thousands_sep"} # There are legal locales where 'mon_decimal_point' and # 'mon_thousands_sep' are both "" (the empty string) && ($prefix eq "" || $self->{"mon_decimal_point"} ne ""); } } ##---------------------------------------------------------------------- # _get_multipliers returns the multipliers to be used for kilo, mega, # giga, and tera (un-)formatting. Used in format_bytes and unformat_number. # For internal use only. sub _get_multipliers { my($base) = @_; if (!defined($base) || $base == 1024) { # the "tera" value is not portable, but that's a matter for the caller no warnings 'portable'; return ( kilo => 0x00000000400, mega => 0x00000100000, giga => 0x00040000000, tera => 0x10000000000); } elsif ($base == 1000) { return ( kilo => 1_000, mega => 1_000_000, giga => 1_000_000_000, tera => 1_000_000_000_000 ); } else { croak "base overflow" if $base **3 > MAX_INT; croak "base must be a positive integer" unless $base > 0 && $base == int($base); return ( kilo => $base, mega => $base ** 2, giga => $base ** 3, tera => $base ** 4); } } ##---------------------------------------------------------------------- # _complain_undef displays a warning message on STDERR and is called # when a subroutine has been invoked with an undef value. A warning # message is printed if the calling environment has "uninitialized" # warnings enabled. sub _complain_undef { my @stack; my($sub, $bitmask) = (caller(1))[3,9]; my $offset = $warnings::Offsets{"uninitialized"}; carp "Use of uninitialized value in call to $sub" if vec($bitmask, $offset, 1); } ##---------------------------------------------------------------------- #pod =method new #pod #pod my $formatter = Number::Format->new( %args ); #pod #pod Creates a new Number::Format object. Valid keys for %args are any of #pod the parameters described above. Keys may be in all uppercase or all #pod lowercase, and may optionally be preceded by a hyphen (-) character. #pod Example: #pod #pod my $de = Number::Format->new(-thousands_sep => '.', #pod -decimal_point => ',', #pod -int_curr_symbol => 'DEM'); #pod #pod =cut sub new { my $type = shift; my %args = @_; # Fetch defaults from current locale, or failing that, using globals my $me = {}; # my $locale = setlocale(LC_ALL, ""); my $locale_values = localeconv(); # Strip out illegal negative values from the current locale foreach ( @IGNORE_NEGATIVE ) { if (defined($locale_values->{$_}) && $locale_values->{$_} eq '-1') { delete $locale_values->{$_}; } } while(my($arg, $default) = each %$DEFAULT_LOCALE) { $me->{$arg} = (( exists $locale_values->{$arg}) && $locale_values->{$arg} ne "") ? $locale_values->{$arg} : $default; foreach ($arg, uc $arg, "-$arg", uc "-$arg") { next unless defined $args{$_}; $me->{$arg} = $args{$_}; delete $args{$_}; last; } } # # Some locales set the decimal_point to "," and the thousands_sep to "". # This module generally defaults an empty thousands_sep to ",", creating a # conflict in such a locale. Instead, leave the thousands_sep as the # empty string. Suggested by Moritz Onken. foreach my $prefix ("", "mon_") { $me->{"${prefix}thousands_sep"} = "" if ($me->{"${prefix}decimal_point"} eq $me->{"${prefix}thousands_sep"}); } croak "Invalid argument(s)" if %args; bless $me, $type; $me; } ##---------------------------------------------------------------------- #pod =method round #pod #pod my $str = $formatter->($number, $precision); #pod #pod Rounds the number to the specified precision. If C<$precision> is #pod omitted, the value of the C parameter is used (default #pod value 2). Both input and output are numeric (the function uses math #pod operators rather than string manipulation to do its job), The value of #pod C<$precision> may be any integer, positive or negative. Examples: #pod #pod round(3.14159) yields 3.14 #pod round(3.14159, 4) yields 3.1416 #pod round(42.00, 4) yields 42 #pod round(1234, -2) yields 1200 #pod #pod Since this is a mathematical rather than string oriented function, #pod there will be no trailing zeroes to the right of the decimal point, #pod and the C and C variables are ignored. #pod To format your number using the C and C #pod variables, use C instead. #pod #pod =cut sub round { my ($self, $number, $precision) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } $precision = $self->{decimal_digits} unless defined $precision; $precision = 2 unless defined $precision; croak("precision must be integer") unless int($precision) == $precision; if (ref($number) && $number->isa("Math::BigFloat")) { my $rounded = $number->copy(); $rounded->precision(-$precision); return $rounded; } my $sign = $number <=> 0; my $multiplier = (10 ** $precision); my $result = abs($number); my $product = $result * $multiplier; croak "round() overflow. Try smaller precision or use Math::BigFloat" if $product > MAX_INT; # We need to add 1e-14 to avoid some rounding errors due to the # way floating point numbers work - see string-eq test in t/round.t $result = int($product + .5 + 1e-14) / $multiplier; $result = -$result if $sign < 0; return $result; } ##---------------------------------------------------------------------- #pod =method format_number #pod #pod my $str = $formatter->format_number($number, $precision, $trailing_zeroes); #pod #pod Formats a number by adding C between each set of 3 #pod digits to the left of the decimal point, substituting C #pod for the decimal point, and rounding to the specified precision using #pod C. Note that C<$precision> is a I precision #pod specifier; trailing zeroes will only appear in the output if #pod C<$trailing_zeroes> is provided, or the parameter C is #pod set, with a value that is true (not zero, undef, or the empty string). #pod If C<$precision> is omitted, the value of the C #pod parameter (default value of 2) is used. #pod #pod If the value is too large or great to work with as a regular number, #pod but instead must be shown in scientific notation, returns that number #pod in scientific notation without further formatting. #pod #pod Examples: #pod #pod format_number(12345.6789) yields '12,345.68' #pod format_number(123456.789, 2) yields '123,456.79' #pod format_number(1234567.89, 2) yields '1,234,567.89' #pod format_number(1234567.8, 2) yields '1,234,567.8' #pod format_number(1234567.8, 2, 1) yields '1,234,567.80' #pod format_number(1.23456789, 6) yields '1.234568' #pod format_number("0.000020000E+00", 7);' yields '2e-05' #pod #pod Of course the output would have your values of C and #pod C instead of ',' and '.' respectively. #pod #pod =cut sub format_number { my ($self, $number, $precision, $trailing_zeroes, $mon) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } $self->_check_seps(); # first make sure the SEP variables are valid my($thousands_sep, $decimal_point) = $mon ? @$self{qw(mon_thousands_sep mon_decimal_point)} : @$self{qw(thousands_sep decimal_point)}; # Set defaults and standardize number $precision = $self->{decimal_digits} unless defined $precision; $trailing_zeroes = $self->{decimal_fill} unless defined $trailing_zeroes; # Handle negative numbers my $sign = $number <=> 0; $number = abs($number) if $sign < 0; $number = $self->round($number, $precision); # round off $number # detect scientific notation my $exponent = 0; if ($number =~ /^(-?[\d.]+)e([+-]\d+)$/) { # Don't attempt to format numbers that require scientific notation. return ($sign < 0) ? $self->format_negative($number) : $number; } # Split integer and decimal parts of the number and add commas my $integer = int($number); my $decimal; # Note: In perl 5.6 and up, string representation of a number # automagically includes the locale decimal point. This way we # will detect the decimal part correctly as long as the decimal # point is 1 character. $decimal = substr($number, length($integer)+1) if (length($integer) < length($number)); $decimal = '' unless defined $decimal; # Add trailing 0's if $trailing_zeroes is set. $decimal .= '0'x( $precision - length($decimal) ) if $trailing_zeroes && $precision > length($decimal); # Add the commas (or whatever is in thousands_sep). If # thousands_sep is the empty string, do nothing. if ($thousands_sep) { # Add leading 0's so length($integer) is divisible by 3 $integer = '0'x(3 - (length($integer) % 3)).$integer; # Split $integer into groups of 3 characters and insert commas $integer = join($thousands_sep, grep {$_ ne ''} split(/(...)/, $integer)); # Strip off leading zeroes and optional thousands separator $integer =~ s/^0+(?:\Q$thousands_sep\E)?//; } $integer = '0' if $integer eq ''; # Combine integer and decimal parts and return the result. my $result = ((defined $decimal && length $decimal) ? join($decimal_point, $integer, $decimal) : $integer); return ($sign < 0) ? $self->format_negative($result) : $result; } ##---------------------------------------------------------------------- #pod =method format_negative #pod #pod my $str = $formatter->($number, $picture); #pod #pod Formats a negative number. Picture should be a string that contains #pod the letter C where the number should be inserted. For example, for #pod standard negative numbers you might use ``C<-x>'', while for #pod accounting purposes you might use ``C<(x)>''. If the specified number #pod begins with a ``-'' character, that will be removed before formatting, #pod but formatting will occur whether or not the number is negative. #pod #pod =cut sub format_negative { my($self, $number, $format) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } $format = $self->{neg_format} unless defined $format; croak "Letter x must be present in picture in format_negative()" unless $format =~ /x/; $number =~ s/^-//; $format =~ s/x/$number/; return $format; } ##---------------------------------------------------------------------- #pod =method format_picture #pod #pod my $str = $formatter->format_picture($number, $picture); #pod #pod Returns a string based on C<$picture> with the C<#> characters #pod replaced by digits from C<$number>. If the length of the integer part #pod of $number is too large to fit, the C<#> characters are replaced with #pod asterisks (C<*>) instead. Examples: #pod #pod format_picture(100.023, 'USD ##,###.##') yields 'USD 100.02' #pod format_picture(1000.23, 'USD ##,###.##') yields 'USD 1,000.23' #pod format_picture(10002.3, 'USD ##,###.##') yields 'USD 10,002.30' #pod format_picture(100023, 'USD ##,###.##') yields 'USD **,***.**' #pod format_picture(1.00023, 'USD #.###,###') yields 'USD 1.002,300' #pod #pod The comma (,) and period (.) you see in the picture examples should #pod match the values of C and C, #pod respectively, for proper operation. However, the C #pod characters in C<$picture> need not occur every three digits; the #pod I use of that variable by this function is to remove leading #pod commas (see the first example above). There may not be more than one #pod instance of C in C<$picture>. #pod #pod The value of C is used to determine how negative numbers #pod are displayed. The result of this is that the output of this function #pod my have unexpected spaces before and/or after the number. This is #pod necessary so that positive and negative numbers are formatted into a #pod space the same size. If you are only using positive numbers and want #pod to avoid this problem, set NEG_FORMAT to "x". #pod #pod =cut sub format_picture { my ($self, $number, $picture) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } croak "Picture not defined" unless defined($picture); $self->_check_seps(); # Handle negative numbers # A neg_format like "x" has no prefix, and the match fails, so default to # the empty string rather than warning about undef. (RT#148306) # -- claude, 2026-09-16 my($neg_prefix) = $self->{neg_format} =~ /^([^x]+)/; $neg_prefix = '' unless defined $neg_prefix; my($pic_prefix) = $picture =~ /^([^\#]+)/; my $neg_pic = $self->{neg_format}; (my $pos_pic = $self->{neg_format}) =~ s/[^x\s]/ /g; (my $pos_prefix = $neg_prefix) =~ s/[^x\s]/ /g; $neg_pic =~ s/x/$picture/; $pos_pic =~ s/x/$picture/; my $sign = $number <=> 0; $number = abs($number) if $sign < 0; $picture = $sign < 0 ? $neg_pic : $pos_pic; my $sign_prefix = $sign < 0 ? $neg_prefix : $pos_prefix; # Split up the picture and die if there is more than one $DECIMAL_POINT my($pic_int, $pic_dec, @cruft) = split(/\Q$self->{decimal_point}\E/, $picture); $pic_int = '' unless defined $pic_int; $pic_dec = '' unless defined $pic_dec; croak "Only one decimal separator permitted in picture" if @cruft; # Obtain precision from the length of the decimal part... my $precision = $pic_dec; # start with copying it $precision =~ s/[^\#]//g; # eliminate all non-# characters $precision = length $precision; # take the length of the result # Format the number $number = $self->round($number, $precision); # Obtain the length of the integer portion just like we did for $precision my $intsize = $pic_int; # start with copying it $intsize =~ s/[^\#]//g; # eliminate all non-# characters $intsize = length $intsize; # take the length of the result # Split up $number same as we did for $picture earlier my($num_int, $num_dec) = split(/\./, $number, 2); $num_int = '' unless defined $num_int; $num_dec = '' unless defined $num_dec; # Check if the integer part will fit in the picture if (length $num_int > $intsize) { $picture =~ s/\#/\*/g; # convert # to * and return it $pic_prefix = "" unless defined $pic_prefix; $picture =~ s/^(\Q$sign_prefix\E)(\Q$pic_prefix\E)(\s*)/$2$3$1/; return $picture; } # Split each portion of number and picture into arrays of characters my @num_int = split(//, $num_int); my @num_dec = split(//, $num_dec); my @pic_int = split(//, $pic_int); my @pic_dec = split(//, $pic_dec); # Now we copy those characters into @result. my @result; @result = ($self->{decimal_point}) if $picture =~ /\Q$self->{decimal_point}\E/; # For each characture in the decimal part of the picture, replace '#' # signs with digits from the number. my $char; foreach $char (@pic_dec) { $char = (shift(@num_dec) || 0) if ($char eq '#'); push (@result, $char); } # For each character in the integer part of the picture (moving right # to left this time), replace '#' signs with digits from the number, # or spaces if we've run out of numbers. while ($char = pop @pic_int) { $char = pop(@num_int) if ($char eq '#'); $char = ' ' if (!defined($char) || $char eq $self->{thousands_sep} && $#num_int < 0); unshift (@result, $char); } # Combine @result into a string and return it. my $result = join('', @result); $sign_prefix = '' unless defined $sign_prefix; $pic_prefix = '' unless defined $pic_prefix; $result =~ s/^(\Q$sign_prefix\E)(\Q$pic_prefix\E)(\s*)/$2$3$1/; $result; } ##---------------------------------------------------------------------- #pod =method format_price #pod #pod my $str = $formatter->format_price($number, $precision, $symbol); #pod #pod Returns a string containing C<$number> formatted similarly to #pod C, except that the decimal portion may have trailing #pod zeroes added to make it be exactly C<$precision> characters long, and #pod the currency string will be prefixed. #pod #pod The C<$symbol> attribute may be one of "INT_CURR_SYMBOL" or #pod "CURRENCY_SYMBOL" (case insensitive) to use the value of that #pod attribute of the object, or a string containing the symbol to be used. #pod The default is "INT_CURR_SYMBOL" if this argument is undefined or not #pod given; if set to the empty string, or if set to undef and the #pod C attribute of the object is the empty string, no #pod currency will be added. #pod #pod Negative prices are laid out according to the locale's monetary sign #pod rules: C, C, C, and #pod C. Unlike C, C does #pod I consult C. To show negative prices in parentheses, #pod for example, set C to 0 rather than setting C #pod to C<(x)>. #pod #pod If C<$precision> is not provided, the default of 2 will be used. #pod Examples: #pod #pod format_price(12.95) yields 'USD 12.95' #pod format_price(12) yields 'USD 12.00' #pod format_price(12, 3) yields '12.000' #pod #pod The third example assumes that C is the empty string. #pod #pod =cut sub format_price { my ($self, $number, $precision, $curr_symbol) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } # Determine what the monetary symbol should be $curr_symbol = $self->{int_curr_symbol} if (!defined($curr_symbol) || lc($curr_symbol) eq "int_curr_symbol"); $curr_symbol = $self->{currency_symbol} if (!defined($curr_symbol) || lc($curr_symbol) eq "currency_symbol"); $curr_symbol = "" unless defined($curr_symbol); # Determine which value to use for frac digits my $frac_digits = ($curr_symbol eq $self->{int_curr_symbol} ? $self->{int_frac_digits} : $self->{frac_digits}); # Determine precision for decimal portion $precision = $frac_digits unless defined $precision; $precision = $self->{decimal_digits} unless defined $precision; # fallback $precision = 2 unless defined $precision; # default # Determine sign and absolute value my $sign = $number <=> 0; $number = abs($number) if $sign < 0; # format it first $number = $self->format_number($number, $precision, undef, 1); # Now we make sure the decimal part has enough zeroes my ($integer, $decimal) = split(/\Q$self->{mon_decimal_point}\E/, $number, 2); $decimal = '0'x$precision unless $decimal; $decimal .= '0'x($precision - length $decimal); # Extract positive or negative values my($sep_by_space, $cs_precedes, $sign_posn, $sign_symbol); if ($sign < 0) { $sep_by_space = $self->{n_sep_by_space}; $cs_precedes = $self->{n_cs_precedes}; $sign_posn = $self->{n_sign_posn}; $sign_symbol = $self->{negative_sign}; } else { $sep_by_space = $self->{p_sep_by_space}; $cs_precedes = $self->{p_cs_precedes}; $sign_posn = $self->{p_sign_posn}; $sign_symbol = $self->{positive_sign}; } # Combine it all back together. my $result = ($precision ? join($self->{mon_decimal_point}, $integer, $decimal) : $integer); # Determine where spaces go, if any my($sign_sep, $curr_sep); if ($sep_by_space == 0) { $sign_sep = $curr_sep = ""; } elsif ($sep_by_space == 1) { $sign_sep = ""; $curr_sep = " "; } elsif ($sep_by_space == 2) { $sign_sep = " "; $curr_sep = ""; } else { croak "Invalid sep_by_space value"; } # Add sign, if any if ($sign_posn >= 0 && $sign_posn <= 2) { # Combine with currency symbol and return if ($curr_symbol ne "") { if ($cs_precedes) { $result = $curr_symbol.$curr_sep.$result; } else { $result = $result.$curr_sep.$curr_symbol; } } if ($sign_posn == 0) { return "($result)"; } elsif ($sign_posn == 1) { return $sign_symbol.$sign_sep.$result; } else # $sign_posn == 2 { return $result.$sign_sep.$sign_symbol; } } elsif ($sign_posn == 3 || $sign_posn == 4) { if ($sign_posn == 3) { $curr_symbol = $sign_symbol.$sign_sep.$curr_symbol; } else # $sign_posn == 4 { $curr_symbol = $curr_symbol.$sign_sep.$sign_symbol; } # Combine with currency symbol and return if ($cs_precedes) { return $curr_symbol.$curr_sep.$result; } else { return $result.$curr_sep.$curr_symbol; } } else { croak "Invalid *_sign_posn value"; } } ##---------------------------------------------------------------------- #pod =method format_bytes #pod #pod my $str = $formatter->format_bytes($number, %options); #pod #pod my $str = $formatter->format_bytes($number, $precision); # deprecated #pod #pod Returns a string containing C<$number> formatted similarly to #pod C, except that large numbers may be abbreviated by #pod adding a suffix to indicate 1024, 1,048,576, or 1,073,741,824 bytes. #pod Suffix may be the traditional K, M, or G (default); or the IEC #pod standard 60027 "KiB," "MiB," or "GiB" depending on the "mode" option. #pod #pod Negative values will result in an error. #pod #pod The abbreviated value is passed through C, so the #pod object's C, C, and C #pod settings all apply, and there is no per-call option to override them. #pod In particular, to get trailing zeroes (for aligning a column of sizes, #pod say) build the formatter with C<< decimal_fill => 1 >>: #pod #pod Number::Format->new->format_bytes(2048) yields 2K #pod Number::Format->new(decimal_fill => 1)->format_bytes(2048) yields 2.00K #pod #pod The second parameter can be either a hash that sets options, or a #pod number. Using a number here is deprecated and will generate a #pod warning; early versions of Number::Format only allowed a numeric #pod value. A future release of Number::Format will change this warning to #pod an error. New code should use a hash instead to set options. If it #pod is a number this sets the value of the "precision" option. #pod #pod Valid options are: #pod #pod =over 4 #pod #pod =item precision #pod #pod Set the precision for displaying numbers. If not provided, a default #pod of 2 will be used. Examples: #pod #pod format_bytes(12.95) yields '12.95' #pod format_bytes(12.95, precision => 0) yields '13' #pod format_bytes(2048) yields '2K' #pod format_bytes(2048, mode => "iec") yields '2KiB' #pod format_bytes(9999999) yields '9.54M' #pod format_bytes(9999999, precision => 1) yields '9.5M' #pod #pod =item unit #pod #pod Sets the default units used for the results. The default is to #pod determine this automatically in order to minimize the length of the #pod string. In other words, numbers greater than or equal to 1024 (or #pod other number given by the 'base' option, q.v.) will be divided by 1024 #pod and C<$KILO_SUFFIX> or C<$KIBI_SUFFIX> added; if greater than or equal #pod to 1048576 (1024*1024), it will be divided by 1048576 and #pod C<$MEGA_SUFFIX> or C<$MEBI_SUFFIX> appended to the end; etc. #pod #pod However if a value is given for C it will use that value #pod instead. The first letter (case-insensitive) of the value given #pod indicates the threshhold for conversion; acceptable values are T (for #pod tera/tebi), G (for giga/gibi), M (for mega/mebi), K (for kilo/kibi), or #pod A (for automatic, the default). For example: #pod #pod format_bytes(1048576, unit => 'K') yields '1,024K' #pod instead of '1M' #pod #pod Note that the valid values to this option do not vary even when the #pod suffix configuration variables have been changed. #pod #pod =item base #pod #pod Sets the number at which the C<$KILO_SUFFIX> is added. Default is #pod 1024. Set to any value; the only other useful value is probably 1000, #pod as hard disk manufacturers use that number to make their disks sound #pod bigger than they really are. #pod #pod If the mode (see below) is set to "iec" or "iec60027" then setting the #pod base option results in an error. #pod #pod =item mode #pod #pod Traditionally, bytes have been given in SI (metric) units such as #pod "kilo" and "mega" even though they represent powers of 2 (1024, etc.) #pod rather than powers of 10 (1000, etc.) This "binary prefix" causes #pod much confusion in consumer products where "GB" may mean either #pod 1,048,576 or 1,000,000, for example. The International #pod Electrotechnical Commission has created standard IEC 60027 to #pod introduce prefixes Ki, Mi, Gi, etc. ("kibibytes," "mebibytes," #pod "gibibytes," etc.) to remove this confusion. Specify a mode option #pod with either "traditional" or "iec60027" (or abbreviate as "trad" or #pod "iec") to indicate which type of binary prefix you want format_bytes #pod to use. For backward compatibility, "traditional" is the default. #pod See http://en.wikipedia.org/wiki/Binary_prefix for more information. #pod #pod =back #pod #pod =cut sub format_bytes { my ($self, $number, @options) = _get_self @_; unless (defined($number)) { _complain_undef(); $number = 0; } croak "Negative number not allowed in format_bytes" if $number < 0; # If a single scalar is given instead of key/value pairs for # @options, treat that as the value of the precision option. my %options; if (@options == 1) { # To be changed to 'croak' in a future release: carp "format_bytes: number instead of options is deprecated"; %options = ( precision => $options[0] ); } else { %options = @options; } # Set default for precision. Test using defined because it may be 0. $options{precision} = $self->{decimal_digits} unless defined $options{precision}; $options{precision} = 2 unless defined $options{precision}; # default $options{mode} ||= "traditional"; my($ksuff, $msuff, $gsuff, $tsuff); if ($options{mode} =~ /^iec(60027)?$/i) { ($ksuff, $msuff, $gsuff, $tsuff) = @$self{qw(kibi_suffix mebi_suffix gibi_suffix tebi_suffix)}; croak "base option not allowed in iec60027 mode" if exists $options{base}; } elsif ($options{mode} =~ /^trad(itional)?$/i) { ($ksuff, $msuff, $gsuff, $tsuff) = @$self{qw(kilo_suffix mega_suffix giga_suffix tera_suffix)}; } else { croak "Invalid mode"; } # Set default for "base" option. Calculate threshold values for # kilo, mega, giga, and tera values. Useful values of "base" are 1024 or # 1000, but any number can be used. Larger numbers may cause overflows at # some threshholds, of course. my %mult = _get_multipliers($options{base}); # Process "unit" option. Set default, then take first character # and convert to upper case. $options{unit} = "auto" unless defined $options{unit}; my $unit = uc(substr($options{unit},0,1)); # Process "auto" first (default). Based on size of number, # automatically determine which unit to use. if ($unit eq 'A') { if ($number >= $mult{tera}) { $unit = 'T'; } elsif ($number >= $mult{giga}) { $unit = 'G'; } elsif ($number >= $mult{mega}) { $unit = 'M'; } elsif ($number >= $mult{kilo}) { $unit = 'K'; } else { $unit = 'N'; } } # Based on unit, whether specified or determined above, divide the # number and determine what suffix to use. my $suffix = ""; if ($unit eq 'T') { $number /= $mult{tera}; $suffix = $tsuff; } elsif ($unit eq 'G') { $number /= $mult{giga}; $suffix = $gsuff; } elsif ($unit eq 'M') { $number /= $mult{mega}; $suffix = $msuff; } elsif ($unit eq 'K') { $number /= $mult{kilo}; $suffix = $ksuff; } elsif ($unit ne 'N') { croak "Invalid unit option"; } # Format the number and add the suffix. return $self->format_number($number, $options{precision}) . $suffix; } ##---------------------------------------------------------------------- #pod =method unformat_number #pod #pod my $str = $formatter->format_number($formatted); #pod #pod Converts a string as returned by C, #pod C, or C, and returns the #pod corresponding value as a numeric scalar. Returns C if the #pod number does not contain any digits. Examples: #pod #pod unformat_number('USD 12.95') yields 12.95 #pod unformat_number('USD 12.00') yields 12 #pod unformat_number('foobar') yields undef #pod unformat_number('1234-567@.8') yields 1234567.8 #pod #pod The value of C is used to determine where to separate #pod the integer and decimal portions of the input. All other non-digit #pod characters, including but not limited to C and #pod C, are removed. #pod #pod If the number matches the pattern of C I there is a C<-> #pod character before any of the digits, then a negative number is returned. #pod #pod If the number ends with the C, C, #pod C, C, C, C, #pod C, or C characters, then the number returned #pod will be multiplied by the appropriate multiple of 1024 (or if the base #pod option is given, by the multiple of that value) as appropriate. Examples: #pod #pod unformat_number("4K", base => 1024) yields 4096 #pod unformat_number("4K", base => 1000) yields 4000 #pod unformat_number("4KiB", base => 1024) yields 4096 #pod unformat_number("4G") yields 4294967296 #pod #pod =cut sub unformat_number { my ($self, $formatted, %options) = _get_self @_; unless (defined($formatted)) { _complain_undef(); $formatted = ""; } $self->_check_seps(); return undef unless $formatted =~ /\d/; # require at least one digit # Regular expression for detecting decimal point my $pt = qr/\Q$self->{decimal_point}\E/; # ru_RU locale has comma for decimal_point, but period for # mon_decimal_point! But as long as thousands_sep is different # from either, we can allow either decimal point. if ($self->{mon_decimal_point} && $self->{decimal_point} ne $self->{mon_decimal_point} && $self->{decimal_point} ne $self->{mon_thousands_sep} && $self->{mon_decimal_point} ne $self->{thousands_sep}) { $pt = qr/(?:\Q$self->{decimal_point}\E| \Q$self->{mon_decimal_point}\E)/x; } # Detect if it ends with one of the kilo / mega / giga / tera suffixes. my $kp = ($formatted =~ s/\s*($self->{kilo_suffix}|$self->{kibi_suffix})\s*$//); my $mp = ($formatted =~ s/\s*($self->{mega_suffix}|$self->{mebi_suffix})\s*$//); my $gp = ($formatted =~ s/\s*($self->{giga_suffix}|$self->{gibi_suffix})\s*$//); my $tp = ($formatted =~ s/\s*($self->{tera_suffix}|$self->{tebi_suffix})\s*$//); my %mult = _get_multipliers($options{base}); # Split number into integer and decimal parts my ($integer, $decimal, @cruft) = split($pt, $formatted); croak "Only one decimal separator permitted" if @cruft; # It's negative if the first non-digit character is a - my $sign = $formatted =~ /^\D*-/ ? -1 : 1; my($before_re, $after_re) = split /x/, $self->{neg_format}, 2; $sign = -1 if $formatted =~ /\Q$before_re\E(.+)\Q$after_re\E/; # Strip out all non-digits from integer and decimal parts $integer = '' unless defined $integer; $decimal = '' unless defined $decimal; $integer =~ s/\D//g; $decimal =~ s/\D//g; # Join back up, using period, and add 0 to make Perl think it's a number my $number = join('.', $integer, $decimal) + 0; $number = -$number if $sign < 0; # Scale the number if it ended in kilo or mega suffix. $number *= $mult{kilo} if $kp; $number *= $mult{mega} if $mp; $number *= $mult{giga} if $gp; $number *= $mult{tera} if $tp; return $number; } ###--------------------------------------------------------------------- #pod =head1 CAVEATS #pod #pod Some systems, notably OpenBSD, may have incomplete locale support. #pod Using this module together with L in OpenBSD may therefore #pod not produce the intended results. #pod #pod This library takes some pain to cope with numeric precision, but it doesn't #pod solve every problem. Working with terabyte sizes on a 32-bit perl may have #pod imprecise results. #pod #pod =cut 1; __END__ =pod =encoding UTF-8 =head1 NAME Number::Format - Perl extension for formatting numbers =head1 VERSION version 1.79 =head1 SYNOPSIS use Number::Format; my $x = Number::Format->new(%args); $formatted = $x->round($number, $precision); $formatted = $x->format_number($number, $precision, $trailing_zeroes); $formatted = $x->format_negative($number, $picture); $formatted = $x->format_picture($number, $picture); $formatted = $x->format_price($number, $precision, $symbol); $formatted = $x->format_bytes($number, $precision); $number = $x->unformat_number($formatted); use Number::Format qw(:subs); $formatted = round($number, $precision); $formatted = format_number($number, $precision, $trailing_zeroes); $formatted = format_negative($number, $picture); $formatted = format_picture($number, $picture); $formatted = format_price($number, $precision, $symbol); $formatted = format_bytes($number, $precision); $number = unformat_number($formatted); =head1 DESCRIPTION These functions provide an easy means of formatting numbers in a manner suitable for displaying to the user. There are two ways to use this package. One is to declare an object of type Number::Format, which you can think of as a formatting engine. The various functions defined here are provided as object methods. The constructor C can be used to set the parameters of the formatting engine. Valid parameters are: THOUSANDS_SEP - character inserted between groups of 3 digits DECIMAL_POINT - character separating integer and fractional parts MON_THOUSANDS_SEP - like THOUSANDS_SEP, but used for format_price MON_DECIMAL_POINT - like DECIMAL_POINT, but used for format_price INT_CURR_SYMBOL - character(s) denoting currency (see format_price()) DECIMAL_DIGITS - number of digits to the right of dec point (def 2) DECIMAL_FILL - boolean; whether to add zeroes to fill out decimal NEG_FORMAT - format to display negative numbers (def ``-x'') KILO_SUFFIX - suffix to add when format_bytes formats kilobytes (trad) MEGA_SUFFIX - " " " " " " megabytes (trad) GIGA_SUFFIX - " " " " " " gigabytes (trad) TERA_SUFFIX - " " " " " " terabytes (trad) KIBI_SUFFIX - suffix to add when format_bytes formats kibibytes (iec) MEBI_SUFFIX - " " " " " " mebibytes (iec) GIBI_SUFFIX - " " " " " " gibibytes (iec) TEBI_SUFFIX - " " " " " " tebibytes (iec) They may be specified in upper or lower case, with or without a leading hyphen ( - ). If C is set to the empty string, format_number will not insert any separators. The defaults for C, C, C, C, and C come from the POSIX locale information (see L). If your POSIX locale does not provide C and/or C fields, then the C and/or C values are used for those parameters. Formerly, POSIX was optional but this caused problems in some cases, so it is now required. If this causes you hardship, please contact the author of this package at (remove "SPAM" to get correct email address) for help. If any of the above parameters are not specified when you invoke C, the values are taken from the current locale, and failing that from these built-in defaults: THOUSANDS_SEP = ',' DECIMAL_POINT = '.' MON_THOUSANDS_SEP = ',' MON_DECIMAL_POINT = '.' INT_CURR_SYMBOL = 'USD' DECIMAL_DIGITS = 2 DECIMAL_FILL = 0 NEG_FORMAT = '-x' KILO_SUFFIX = 'K' MEGA_SUFFIX = 'M' GIGA_SUFFIX = 'G' TERA_SUFFIX = 'T' KIBI_SUFFIX = 'KiB' MEBI_SUFFIX = 'MiB' GIBI_SUFFIX = 'GiB' TEBI_SUFFIX = 'TiB' Note however that when you first call one of the functions in this module I using the object-oriented interface, further setting of those global variables will have no effect on non-OO calls. It is recommended that you use the object-oriented interface instead for fewer headaches and a cleaner design. The C and C values are not set by the Locale system, but are definable by the user. They affect the output of C. Setting C is like giving that value as the C<$precision> argument to that function. Setting C to a true value causes C to append zeroes to the right of the decimal digits until the length is the specified number of digits. C is only used by C and is a string containing the letter 'x', where that letter will be replaced by a positive representation of the number being passed to that function. C and C utilize this feature by calling C if the number was less than 0. C, C, C, and C are used by C when the value is over 1024, 1024**2, 1024**3, or 1024**4, respectively. The default values are "K", "M", "G", and "T". These apply in the default "traditional" mode only. C, C, C, and C are used by C when the value is over 1024, 1024**2, 1024**3, or 1024**4, respectively. The default values are "KiB", "MiB", "GiB", "TiB". These apply in the "iso60027" mode only. The only restrictions on C and C are that they must not be digits and must not be identical. There are no restrictions on C. For example, a German user might include this in their code: use Number::Format; my $de = Number::Format->new(-thousands_sep => '.', -decimal_point => ',', -int_curr_symbol => 'DEM'); my $formatted = $de->format_number($number); Or, if you prefer not to use the object oriented interface, you can call the functions directly: use Number::Format qw(:subs); my $formatted = format_number($number); In that case the parameters come from the current locale and the built-in defaults, and there is no way to override them. If you need non-default parameters, use the object oriented interface. =head1 PERL VERSION This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years. Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. =head1 METHODS =head2 new my $formatter = Number::Format->new( %args ); Creates a new Number::Format object. Valid keys for %args are any of the parameters described above. Keys may be in all uppercase or all lowercase, and may optionally be preceded by a hyphen (-) character. Example: my $de = Number::Format->new(-thousands_sep => '.', -decimal_point => ',', -int_curr_symbol => 'DEM'); =head2 round my $str = $formatter->($number, $precision); Rounds the number to the specified precision. If C<$precision> is omitted, the value of the C parameter is used (default value 2). Both input and output are numeric (the function uses math operators rather than string manipulation to do its job), The value of C<$precision> may be any integer, positive or negative. Examples: round(3.14159) yields 3.14 round(3.14159, 4) yields 3.1416 round(42.00, 4) yields 42 round(1234, -2) yields 1200 Since this is a mathematical rather than string oriented function, there will be no trailing zeroes to the right of the decimal point, and the C and C variables are ignored. To format your number using the C and C variables, use C instead. =head2 format_number my $str = $formatter->format_number($number, $precision, $trailing_zeroes); Formats a number by adding C between each set of 3 digits to the left of the decimal point, substituting C for the decimal point, and rounding to the specified precision using C. Note that C<$precision> is a I precision specifier; trailing zeroes will only appear in the output if C<$trailing_zeroes> is provided, or the parameter C is set, with a value that is true (not zero, undef, or the empty string). If C<$precision> is omitted, the value of the C parameter (default value of 2) is used. If the value is too large or great to work with as a regular number, but instead must be shown in scientific notation, returns that number in scientific notation without further formatting. Examples: format_number(12345.6789) yields '12,345.68' format_number(123456.789, 2) yields '123,456.79' format_number(1234567.89, 2) yields '1,234,567.89' format_number(1234567.8, 2) yields '1,234,567.8' format_number(1234567.8, 2, 1) yields '1,234,567.80' format_number(1.23456789, 6) yields '1.234568' format_number("0.000020000E+00", 7);' yields '2e-05' Of course the output would have your values of C and C instead of ',' and '.' respectively. =head2 format_negative my $str = $formatter->($number, $picture); Formats a negative number. Picture should be a string that contains the letter C where the number should be inserted. For example, for standard negative numbers you might use ``C<-x>'', while for accounting purposes you might use ``C<(x)>''. 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. =head2 format_picture my $str = $formatter->format_picture($number, $picture); Returns a string based on C<$picture> with the C<#> characters replaced by digits from C<$number>. If the length of the integer part of $number is too large to fit, the C<#> characters are replaced with asterisks (C<*>) instead. Examples: format_picture(100.023, 'USD ##,###.##') yields 'USD 100.02' format_picture(1000.23, 'USD ##,###.##') yields 'USD 1,000.23' format_picture(10002.3, 'USD ##,###.##') yields 'USD 10,002.30' format_picture(100023, 'USD ##,###.##') yields 'USD **,***.**' format_picture(1.00023, 'USD #.###,###') yields 'USD 1.002,300' The comma (,) and period (.) you see in the picture examples should match the values of C and C, respectively, for proper operation. However, the C characters in C<$picture> need not occur every three digits; the I use of that variable by this function is to remove leading commas (see the first example above). There may not be more than one instance of C in C<$picture>. The value of C is used to determine how negative numbers are displayed. The result of this is that the output of this function my have unexpected spaces before and/or after the number. This is necessary so that positive and negative numbers are formatted into a space the same size. If you are only using positive numbers and want to avoid this problem, set NEG_FORMAT to "x". =head2 format_price my $str = $formatter->format_price($number, $precision, $symbol); Returns a string containing C<$number> formatted similarly to C, except that the decimal portion may have trailing zeroes added to make it be exactly C<$precision> characters long, and the currency string will be prefixed. The C<$symbol> attribute may be one of "INT_CURR_SYMBOL" or "CURRENCY_SYMBOL" (case insensitive) to use the value of that attribute of the object, or a string containing the symbol to be used. The default is "INT_CURR_SYMBOL" if this argument is undefined or not given; if set to the empty string, or if set to undef and the C attribute of the object is the empty string, no currency will be added. Negative prices are laid out according to the locale's monetary sign rules: C, C, C, and C. Unlike C, C does I consult C. To show negative prices in parentheses, for example, set C to 0 rather than setting C to C<(x)>. If C<$precision> is not provided, the default of 2 will be used. Examples: format_price(12.95) yields 'USD 12.95' format_price(12) yields 'USD 12.00' format_price(12, 3) yields '12.000' The third example assumes that C is the empty string. =head2 format_bytes my $str = $formatter->format_bytes($number, %options); my $str = $formatter->format_bytes($number, $precision); # deprecated Returns a string containing C<$number> formatted similarly to C, except that large numbers may be abbreviated by adding a suffix to indicate 1024, 1,048,576, or 1,073,741,824 bytes. Suffix may be the traditional K, M, or G (default); or the IEC standard 60027 "KiB," "MiB," or "GiB" depending on the "mode" option. Negative values will result in an error. The abbreviated value is passed through C, so the object's C, C, and C settings all apply, and there is no per-call option to override them. In particular, to get trailing zeroes (for aligning a column of sizes, say) build the formatter with C<< decimal_fill => 1 >>: Number::Format->new->format_bytes(2048) yields 2K Number::Format->new(decimal_fill => 1)->format_bytes(2048) yields 2.00K The second parameter can be either a hash that sets options, or a number. Using a number here is deprecated and will generate a warning; early versions of Number::Format only allowed a numeric value. A future release of Number::Format will change this warning to an error. New code should use a hash instead to set options. If it is a number this sets the value of the "precision" option. Valid options are: =over 4 =item precision Set the precision for displaying numbers. If not provided, a default of 2 will be used. Examples: format_bytes(12.95) yields '12.95' format_bytes(12.95, precision => 0) yields '13' format_bytes(2048) yields '2K' format_bytes(2048, mode => "iec") yields '2KiB' format_bytes(9999999) yields '9.54M' format_bytes(9999999, precision => 1) yields '9.5M' =item unit Sets the default units used for the results. The default is to determine this automatically in order to minimize the length of the string. In other words, numbers greater than or equal to 1024 (or other number given by the 'base' option, q.v.) will be divided by 1024 and C<$KILO_SUFFIX> or C<$KIBI_SUFFIX> added; if greater than or equal to 1048576 (1024*1024), it will be divided by 1048576 and C<$MEGA_SUFFIX> or C<$MEBI_SUFFIX> appended to the end; etc. However if a value is given for C it will use that value instead. The first letter (case-insensitive) of the value given indicates the threshhold for conversion; acceptable values are T (for tera/tebi), G (for giga/gibi), M (for mega/mebi), K (for kilo/kibi), or A (for automatic, the default). For example: format_bytes(1048576, unit => 'K') yields '1,024K' instead of '1M' Note that the valid values to this option do not vary even when the suffix configuration variables have been changed. =item base Sets the number at which the C<$KILO_SUFFIX> is added. Default is 1024. Set to any value; the only other useful value is probably 1000, as hard disk manufacturers use that number to make their disks sound bigger than they really are. If the mode (see below) is set to "iec" or "iec60027" then setting the base option results in an error. =item mode Traditionally, bytes have been given in SI (metric) units such as "kilo" and "mega" even though they represent powers of 2 (1024, etc.) rather than powers of 10 (1000, etc.) This "binary prefix" causes much confusion in consumer products where "GB" may mean either 1,048,576 or 1,000,000, for example. The International Electrotechnical Commission has created standard IEC 60027 to introduce prefixes Ki, Mi, Gi, etc. ("kibibytes," "mebibytes," "gibibytes," etc.) to remove this confusion. Specify a mode option with either "traditional" or "iec60027" (or abbreviate as "trad" or "iec") to indicate which type of binary prefix you want format_bytes to use. For backward compatibility, "traditional" is the default. See http://en.wikipedia.org/wiki/Binary_prefix for more information. =back =head2 unformat_number my $str = $formatter->format_number($formatted); Converts a string as returned by C, C, or C, and returns the corresponding value as a numeric scalar. Returns C if the number does not contain any digits. Examples: unformat_number('USD 12.95') yields 12.95 unformat_number('USD 12.00') yields 12 unformat_number('foobar') yields undef unformat_number('1234-567@.8') yields 1234567.8 The value of C is used to determine where to separate the integer and decimal portions of the input. All other non-digit characters, including but not limited to C and C, are removed. If the number matches the pattern of C I there is a C<-> character before any of the digits, then a negative number is returned. If the number ends with the C, C, C, C, C, C, C, or C characters, then the number returned will be multiplied by the appropriate multiple of 1024 (or if the base option is given, by the multiple of that value) as appropriate. Examples: unformat_number("4K", base => 1024) yields 4096 unformat_number("4K", base => 1000) yields 4000 unformat_number("4KiB", base => 1024) yields 4096 unformat_number("4G") yields 4294967296 =head1 EXPORTS Nothing is exported by default. To export functions, name them on the import list of the C statement, or use the tag C<:subs> to export all of them. The tag C<:vars> (and the variables half of C<:all>) still exists for compatibility, but it no longer has any useful purpose. It exports a set of package variables that were once the way to configure the functional interface; assigning to them has had no effect since version 1.60 in 2008. Use C instead. =head1 CAVEATS Some systems, notably OpenBSD, may have incomplete locale support. Using this module together with L in OpenBSD may therefore not produce the intended results. This library takes some pain to cope with numeric precision, but it doesn't solve every problem. Working with terabyte sizes on a 32-bit perl may have imprecise results. =head1 AUTHOR William R. Ward =head1 CONTRIBUTORS =for stopwords Karl Williamson Ricardo Signes =over 4 =item * Karl Williamson =item * Ricardo Signes =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 1997 by William R. Ward . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut 00-report-prereqs.t100644000765000024 1360115252747227 17332 0ustar00rjbsstaff000000000000Number-Format-1.79/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.029 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if grep { $_ eq $mod } @exclude; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; if ($mod eq 'perl') { push @reports, ['perl', $want, $]]; next; } my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: author000755000765000024 015252747227 15247 5ustar00rjbsstaff000000000000Number-Format-1.79/xtpod-syntax.t100644000765000024 25115252747227 17660 0ustar00rjbsstaff000000000000Number-Format-1.79/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644000765000024 332415252747227 17437 0ustar00rjbsstaff000000000000Number-Format-1.79/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.78' } }, 'develop' => { 'requires' => { 'Encode' => '0', 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Test::More' => '0.94', 'Test::Pod' => '1.41', 'strict' => '0' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Exporter' => '0', 'POSIX' => '0', 'base' => '0', 'constant' => '0', 'perl' => '5.012', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Test::More' => '0.96', 'strict' => '0' } } }; $x; }00-compile.t100644000765000024 252315252747227 17443 0ustar00rjbsstaff000000000000Number-Format-1.79/xt/authoruse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.059 use Test::More 0.94; plan tests => 2; my @module_files = ( 'Number/Format.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', explain(\@warnings); BAIL_OUT("Compilation problems") if !Test::More->builder->is_passing; release000755000765000024 015252747227 15365 5ustar00rjbsstaff000000000000Number-Format-1.79/xtchanges_has_content.t100644000765000024 210015252747227 21700 0ustar00rjbsstaff000000000000Number-Format-1.79/xt/releaseuse Test::More tests => 2; note 'Checking Changes'; my $changes_file = 'Changes'; my $newver = '1.79'; my $trial_token = '-TRIAL'; my $encoding = 'UTF-8'; SKIP: { ok(-e $changes_file, "$changes_file file exists") or skip 'Changes is missing', 1; ok(_get_changes($newver), "$changes_file has content for $newver"); } done_testing; sub _get_changes { my $newver = shift; # parse changelog to find commit message open(my $fh, '<', $changes_file) or die "cannot open $changes_file: $!"; my $changelog = join('', <$fh>); if ($encoding) { require Encode; $changelog = Encode::decode($encoding, $changelog, Encode::FB_CROAK()); } close $fh; my @content = grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented split /\n/, $changelog; shift @content; # drop the version line # drop unindented last line and trailing blank lines pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); # return number of non-blank lines return scalar @content; }