switchsystems/precision-maths

BCMath 扩展的包装器,用于精确的基本和高级数学运算

0.3.1 2015-02-03 09:12 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:43:39 UTC


README

本模块提供了使用 BC MATH 内部执行精度数学的各种类

有关 BC Math 扩展的更多信息,请参阅 https://php.ac.cn/manual/en/book.bc.php

许可证

本库版权所有 2014, 2015 Switch Systems Ltd,并许可在 Mozilla Public License 2.0 下。

数字类

精度数字类提供了 BC Math 扩展提供的所有基本数学运算

数字是不可变的,并且总是会返回一个新的对象,其中包含操作的结果。

示例

$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' 

数字集合类

数字集合可以用数组作为第一个参数来实例化。它具有对集合执行基本数学运算的各种方法

  • 平均值
  • 中位数
  • 标准差
  • 范围

示例

$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'

税务工具

该实用类可以实例化以执行基本税务操作。它将税率作为构造函数的第一个参数

方法

fetchValueOfTaxToBeAdded

返回将要添加的税值

$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfTaxToBeAdded('125'); // Returns instance of number set to '25'
echo $vat // prints '25'

fetchValueOfAddedTax

返回将要添加的税值

$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfAddedTax('150'); // Returns instance of number set to '25'
echo $vat // prints '25'

addTaxTo

返回将要添加的税值

$vatUtil = new TaxUtility('20');
$priceWithVat = $vatUtil->addTaxTo('125'); // Returns instance of number set to '150'
echo $priceWithVat // prints '150'

removeTaxFrom

返回将要添加的税值

$vatUtil = new TaxUtility('20');
$priceWithVatRemoved = $vatUtil->removeTaxFrom('150'); // Returns instance of number set to '125'
echo $priceWithVatRemoved // prints '125'

财务工具

目前只提供了一个方法

calculatePayForPeriod

$financeUtil = new FinanceUtility();
$pay = $financeUtil->calculatePayForPeriod($startDateTimeObject, $endDateTimeObject, '6.50', '30');

十进制日期时间工具

该类提供了多种方法来计算日期范围内的指定时间单位以及各种转换方法