louisgab/php-calc
Composer 安装命令:
composer require louisgab/php-calc
包简介
Simple fluent float manipulation library
README 文档
README
💯 Simple fluent float manipulation library.
Calc aims to provide tools for easy and readable calculations, without any dependency.
It comes with Number which is an immutable value object that enables fluent float manipulations.
Why
If you ever worked with a codebase full of that kind of crap:
$result = round(($b != 0 ? ((1+$a)/$b) : $c)*0.25, 2)
I'm sure you will enjoy that:
$result = Number::of($b) ->when(Number::of($b)->isZero(), fn($b) => $c fn($b) => Number::one()->plus($a)->divide($b), ) ->multiply(0.25) ->round(2) ->value()
You may think it's like brick/math, which is a really great package, but Calc serves a different purpose.
If floats are good enough for you - and unless you're dealing with sensible data like accounting or science, it should be - then using GMP or bcmath is overkill.
That's what Calc is made for, still using floats while enjoying nice readability.
Another good point is that it handles floating point problems (e.g 0.1 + 0.2 == 0.3 // false) as much as possible, so you don't have to think about it each time (and if you are working with junior developers, it will save them from having problems they didn't even know existed!).
Install
Via composer:
composer require louisgab/php-calc
Usage
Simple as:
use Louisgab\Calc\Number; Number::of($anything);
And good as :
public function carsNeeded(Number $people, Number $placesPerCar): int { return $people->divide($placesPerCar)->round(0)->toInt(); }
Please see DOCS
Testing
composer test
Roadmap
-
Number -
Fraction -
Percentage
Changelog
Please see CHANGELOG
Contributing
Highly welcomed!
License
Please see The MIT License (MIT).
louisgab/php-calc 适用场景与选型建议
louisgab/php-calc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 139 次下载、GitHub Stars 达 16, 最近一次更新时间为 2020 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「fluent」 「number」 「float」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 louisgab/php-calc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 louisgab/php-calc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 louisgab/php-calc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Presentation and Formatting helper with nice fluent interface.
A package for working with arbitrary precision numbers in Laravel.
Traits gathering fluent syntax common methods
A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.
A fluent PHP CURL wrapper
Gambling Algorithms for Certification.
统计信息
- 总下载量: 139
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-22