switchsystems/precision-maths
Composer 安装命令:
composer require switchsystems/precision-maths
包简介
Wrapper for the BCMath extension for precise basic and advanced math operations
README 文档
README
This module provides various classes for performing precision mathematics using BC MATH internally
See http://php.net/manual/en/book.bc.php for more information on the BC Math Extension
Licence
This library is copyright 2014, 2015 Switch Systems Ltd and is licenced under the Mozilla Public License 2.0.
Number Class
The precision number class provides all the basic math operations provides by the BC Math extension
Numbers are immutable and will always return a new object with the value of the operation.
Example:
$number = new Number('20'); // Instatiates Number object with a value of 20
$result = $number->add('20'); // returns a new instance of Number with a value of 40
echo $result; // prints '40'
Number Collection Class
The number collection can be instatiated with an array as the first argument. It has various methods for performing basic math operations on the set
- Mean
- Median
- Standard Deviation
- Range
Example:
$numberCollection = new NumberCollection(['1', '2', '3']);
$mean = $numberCollection->mean(); // returns a new instance of number set to the value of the mean of the set
echo $mean; // prints '2'
Tax Utility
This utility class can be instatiated to perform basic tax operations. It takes tax rate as the first argument of the constructor
Methods:
fetchValueOfTaxToBeAdded
Returns the value of tax that would be added:
$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfTaxToBeAdded('125'); // Returns instance of number set to '25'
echo $vat // prints '25'
fetchValueOfAddedTax
Returns the value of tax that would be added:
$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfAddedTax('150'); // Returns instance of number set to '25'
echo $vat // prints '25'
addTaxTo
Returns the value of tax that would be added:
$vatUtil = new TaxUtility('20');
$priceWithVat = $vatUtil->addTaxTo('125'); // Returns instance of number set to '150'
echo $priceWithVat // prints '150'
removeTaxFrom
Returns the value of tax that would be added:
$vatUtil = new TaxUtility('20');
$priceWithVatRemoved = $vatUtil->removeTaxFrom('150'); // Returns instance of number set to '125'
echo $priceWithVatRemoved // prints '125'
Finance Utility
Currently only provides one method:
calculatePayForPeriod
$financeUtil = new FinanceUtility();
$pay = $financeUtil->calculatePayForPeriod($startDateTimeObject, $endDateTimeObject, '6.50', '30');
Decimal DateTime Utility
This class has a variety of methods for calculating time in a specified unit for a date range and various convertion methods
switchsystems/precision-maths 适用场景与选型建议
switchsystems/precision-maths 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 switchsystems/precision-maths 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 switchsystems/precision-maths 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2015-01-06