illegal/fluent-bcmath
Composer 安装命令:
composer require illegal/fluent-bcmath
包简介
Fluent BCMath is a PHP package designed to simplify the usage of PHP's bcmath functions in a more fluid and intuitive way. With its expressive syntax and Laravel compatibility, it aims to improve the developer experience while working with arbitrary precision arithmetic operations.
README 文档
README
Fluent BcMath is a fluent interface for the PHP BcMath extension.
It helps you to write more readable code, while maintaining the performance of the BcMath extension.
Installation
Install the package via composer:
composer require "illegal/fluent-bcmath"
Usage
You have two options to use the fluent interface.
In both cases, there are two arguments: the number and the scale. The number can be:
- a string
- an integer
- a float
- another
BCNumberinstance
The scale is an integer, which represents the number of digits after the decimal point.
All methods return a new BCNumber instance, so you can chain them.
For example:
use Illegal\FluentBCMath\BCNumber; $num = new BCNumber('1.23', 2); $num->add(2)->sub(2)->mul(2)->div(2)->mod(3)->pow(2)->sqrt();
1. Use the BCNumber class
use Illegal\FluentBCMath\BCNumber; $num = new BCNumber('1.23', 2); // 1st argument is the number, 2nd argument is the scale
2. Use the fnum() helper function
$num = fnum('1.23', 2); // 1st argument is the number, 2nd argument is the scale
Available methods
$num = fnum(10, 2); $num->add(2); // 12.00 $num->sub(2); // 8.00 $num->mul(2); // 20.00 $num->div(2); // 5.00 $num->mod(3); // 1.00 $num->pow(2); // 100.00 $num->sqrt(); // 3.16 $num->equals(10); // true $num->greaterThan(5); // true $num->greaterThanOrEqual(10); // true $num->lessThan(15); // true $num->lessThanOrEqual(10); // true $num->isZero(); // false $num->isPositive(); // true $num->isNegative(); // false $num->isEven(); // true $num->isOdd(); // false $num->abs(); // 10.00 $num->negate(); // -10.00 $num->min(5); // 5.00 $num->max(15); // 15.00 $num->clamp(5, 15); // 10.00
If methods
Each operation has an if method, which returns the result of the operation, if the condition is true.
$num = fnum(10, 2); $num->addIf(2, false); // 10.00 $num->subIf(2, false); // 10.00 $num->mulIf(2, false); // 10.00 $num->divIf(2, false); // 10.00 $num->modIf(3, false); // 10.00 $num->powIf(2, false); // 10.00 $num->sqrtIf(false); // 10.00
Testing
./vendor/bin/pest
License
The MIT License (MIT). Please see License File for more information.
illegal/fluent-bcmath 适用场景与选型建议
illegal/fluent-bcmath 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 725 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「fluent」 「math」 「laravel」 「bcmath」 「Arbitrary-precision」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 illegal/fluent-bcmath 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 illegal/fluent-bcmath 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 illegal/fluent-bcmath 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
Presentation and Formatting helper with nice fluent interface.
Partition problem for balanced arrays splitting made easy.
Traits gathering fluent syntax common methods
Simple, chainable calculation library.
Easy to use arithmetic operations for decimals in PHP (using BCMath)
统计信息
- 总下载量: 725
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-10