Format::Util::Numbers - Miscellaneous routines to do with manipulating number format!
use Format::Util::Numbers qw( commas to_monetary_number_format roundnear formatnumber financialrounding); ...
Round a number near the precision of the supplied one.
roundnear( 0.01, 12345.678) => 12345.68
Produce a more human readbale number with a provided number of decimal points
commas(12345.679, 1) => 12,345.7
Produce a nice human readable number which looks like a currency
to_monetary_number_format(123456789) => 123,456,789.00
This sub is used to format number as per precision defined per currency.
Use this sub only for formatting not for rounding, i.e use this in modules which are used for display purpose only i.e client facing.
DON'T USE THIS FOR CALCULATION, COMPARISON OF NUMBERS DON'T USE THIS FOR QUANTITATIVE ANALYSIS
This sub accepts type i.e whether its price or amount - price e.g. ask price, bid price - amount e.g. balance, deposit/withdraw amount
and takes currency to calculate precision defined per currency.
this subs takes precision defined per currency in config file passed by ENV{FORMAT_UTIL_PRECISION}, else it defaults to precision.yml
Returns string
formatnumber('price', 'USD', 10) => 10.00
This sub is used to round number as per precision defined per currency.
Use this sub only for rounding numbers thats are related to currency like price, amount, balance etc
USE THIS WHEN YOU WANT TO COMPARE NUMBERS RELATED TO CURRENCY USE THIS FOR QUANTITATIVE ANALYSIS FOR NUMBER RELATED TO CURRENCY
financialrounding('amount', 'USD', 10.345) => '10.35'
This sub rounds number as per precision passed, this sub should be used for numbers not related to currencies like probabilities, percentages etc
This sub use round away from zero technique, same as financial rounding, the only difference is it acccepts precision as shown below and has no currency precision
Acceptable precision values format example:
0 1 1e-4 0.0001
This sub only supports rounding to one tenths, hundredths, thousandths and so on. It does not support rounding to two, three tenths, hundredths or so, use roundnear for that.
This sub is created as replacement for roundnear as roundnear for small numbers it does round away from zero, for numbers with more significant digits it's sort-of random
roundcommon(0.01, 10.234) => '10.23'
This is used get complete currency precision config.
Given a currency, this subroutine obtains the smallest possible unit of a currency using the currency's pip size.
For example, if the currency requested is USD, this function will return 0.01.
Everything returned in this function is considered a price.
binary.com, <rakesh at binary.com>
<rakesh at binary.com>
Please report any bugs or feature requests to bug-format-util at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Format-Util. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-format-util at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Format::Util::Numbers
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Format-Util
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Format-Util
CPAN Ratings
http://cpanratings.perl.org/d/Format-Util
Search CPAN
http://search.cpan.org/dist/Format-Util/
Copyright 2014 binary.com.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install Format::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Format::Util
CPAN shell
perl -MCPAN -e shell install Format::Util
For more information on module installation, please visit the detailed CPAN module installation guide.