wsw/money
Composer 安装命令:
composer require wsw/money
包简介
Value Object Money
README 文档
README
Value object for handling monetary values
Installation
Via Composer:
composer require wsw/money
Usage
Instantiating a value:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money('1500.9999', new Currency('USD'));
Output values:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money("1500.9999", new Currency("USD")); echo $money->getAmount(); // (string) 1500.999900 echo $money->getMicros(); // (integer) 1500999900 echo $money->getTruncate(); // (string) 1500.99 echo $money->getRound(); // (string) 1501.00 echo $money->getFormat(); // (string) 1.501,00 echo $money; // (string) 1.501,00
We verify that the values are equal:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money("1500.00", new Currency("USD")); $money2 = new Money("1500.00", new Currency("USD")); $money3 = new Money("1000.00", new Currency("USD")); var_dump($money->equals($money2)); // bool(true) var_dump($money->equals($money3)); // bool(false)
Compare values:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money("1500.00", new Currency("USD")); $money2 = new Money("1500.00", new Currency("USD")); $money3 = new Money("1000.00", new Currency("USD")); // Returns zero (0) when values and currencies are equal. var_dump($money->compare($money2)); // int(0) // Returns one (1) when the left object has the value greater than the right object. var_dump($money->compare($money3)); // int(1) // Returns minus one (-1) when the right object has the value greater than the left object. var_dump($money3->compare($money)); // int(-1)
Add value:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money('100', new Currency('USD')); $addValue = new Money('50', new Currency('USD')); $newMoney = $money->add($addValue); echo $newMoney->getAmount(); // (string) 150.000000 echo $newMoney->getTruncate(); // (string) 150.00 echo $newMoney->getRound(); // (string) 150.00 echo $newMoney->getFormat(); // (string) 150,00 echo $newMoney; // (string) 150,00
Add percentage value:
<?php use WSW\Money\Currency; use WSW\Money\Money; use WSW\Money\Percentage; $money = new Money('100', new Currency('USD')); $percent = new Percentage("75%"); $newMoney = $money->addPercent($percent); echo $newMoney->getAmount(); // (string) 175.000000 echo $newMoney->getTruncate(); // (string) 175.00 echo $newMoney->getRound(); // (string) 175.00 echo $newMoney->getFormat(); // (string) 175,00 echo $newMoney; // (string) 175,00
Subtract value:
<?php use WSW\Money\Currency; use WSW\Money\Money; $money = new Money('100', new Currency('USD')); $subValue = new Money('60.75', new Currency('USD')); $newMoney = $money->sub($subValue); echo $newMoney->getAmount(); // (string) 39.250000 echo $newMoney->getTruncate(); // (string) 39.25 echo $newMoney->getRound(); // (string) 39.25 echo $newMoney->getFormat(); // (string) 39,25 echo $newMoney; // (string) 39,25
Subtract percentage value:
<?php use WSW\Money\Currency; use WSW\Money\Money; use WSW\Money\Percentage; $money = new Money('100', new Currency('USD')); $percent = new Percentage("75%"); $newMoney = $money->subPercent($percent); echo $newMoney->getAmount(); // (string) 25.000000 echo $newMoney->getTruncate(); // (string) 25.00 echo $newMoney->getRound(); // (string) 25.00 echo $newMoney->getFormat(); // (string) 25,00 echo $newMoney; // (string) 25,00
Testing
$ composer test
Security
If you discover any security related issues, please email ronaldo@whera.com.br instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
wsw/money 适用场景与选型建议
wsw/money 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 71.56k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wsw/money 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wsw/money 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 71.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-07