The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Format::Util::Numbers - Miscellaneous routines to do with manipulating number format!

SYNOPSIS

    use Format::Util::Numbers qw( commas to_monetary_number_format roundnear formatnumber financialrounding);
    ...

EXPORT

roundnear

Round a number near the precision of the supplied one.

    roundnear( 0.01, 12345.678) => 12345.68

commas

Produce a more human readbale number with a provided number of decimal points

    commas(12345.679, 1) => 12,345.7

to_monetary_number_format

Produce a nice human readable number which looks like a currency

    to_monetary_number_format(123456789) => 123,456,789.00

formatnumber

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

financialrounding

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

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 number

    financialrounding('amount', 'USD', 10.345) => 10.35

roundcommon

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

Returns number

    roundcommon(0.01, 10.234) => 10.23

get_precision_config

This is used get complete currency precision config.

AUTHOR

binary.com, <rakesh at binary.com>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Format::Util::Numbers

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

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.