ferdiunal/money
Composer 安装命令:
composer require ferdiunal/money
包简介
Simple yet useful money operations for php.
README 文档
README
This package is a fork of the sineld/money repository, with added discount and data types.
ferdiunal/money is a PHP library designed to make working with money easier! There are no static properties or methods. Any number you pass to the class will automatically be prepared for mathematical operations. The class uses , for thousands and . for decimals.
This package can be used with any framework or spaghetti application. If you encounter any issues, feel free to reach out to me by email.
Installation
Via Composer
$ composer require ferdiunal/money
Add the following use statement to the top of your file:
use Ferdiunal\Money\Money;
Then, start using the library!
Non-Composer Users
If you are not using Composer, simply copy the Money.php file located in the src folder to your project and begin using the library. There are no extra dependencies.
Request method aliases
Here are the parameters you can use with methods:
money->setDecimals(default = 2)
money->addTax(default = 18)
money->removeTax(default = 18)
money->setLocaleActive(default = false)
money->setLocaleCode(default = TRL)
money->setLocalePosition(default = prefix, (use "suffix" instead of reverse))
Usage Examples
In the following code example, a currency object is created using the Ferdiunal\Money\Money class. First, a currency object is created based on the specified numeric value. Then, another numeric value is added, subtracted, multiplied, and divided to the currency object. After adding a percentage-based tax, a fixed discount and a percentage-based discount are added. Finally, tax and discount are removed based on the calculations, and the currency object is formatted and retrieved using the get() method. The all() method returns the currency and tax amount as an array. The getTax() method returns the calculated tax amount. The getDiscount() method returns the calculated discount amount.
<?php use Ferdiunal\Money\Money; // Create a new Money instance with a value of 100.50 $money = Money::make(100.50); // Add 50.25 to the Money instance $money->sum(50.25); // Subtract 10.50 from the Money instance $money->subtract(10.50); // Multiply the Money instance by 2 $money->multiply(2); // Divide the Money instance by 3 $money->divide(3); // Add a 20% tax to the Money instance $money->addTax(20); // Add a fixed discount of 15 to the Money instance $money->addDiscount(15, true); // Add a 10% discount to the Money instance $money->addDiscount(10); // Remove the 20% tax from the Money instance $money->removeTax(20); // Enable locale usage and set the locale code to USD $money->setLocaleActive(true)->setLocaleCode('USD'); // Get the Money instance as a formatted string $formattedMoney = $money->get(); // Get the tax amount as a formatted string $taxAmount = $money->getTax(); // Get the discount amount as a formatted string $discountAmount = $money->getDiscount(); // Get the Money instance and tax amount as an array $allData = $money->all(); // Output the formatted string echo $formattedMoney; // $208.00 // Output the tax amount echo $taxAmount; // $31.20 // Output the discount amount echo $discountAmount; // $28.20 // Output the Money instance and tax amount as an array print_r($allData); // Array ( [money] => 179.80 [tax] => 31.20, [discount] => 28.20 )
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
Please see the license file for more information.
ferdiunal/money 适用场景与选型建议
ferdiunal/money 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「money」 「math」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ferdiunal/money 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ferdiunal/money 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ferdiunal/money 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
LaTeX formula to PNG
Partition problem for balanced arrays splitting made easy.
Simple, chainable calculation library.
Easy to use arithmetic operations for decimals in PHP (using BCMath)
Core logic for elegant graphic visualization. Render to SVG, PNG, JPG and Base64.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-07