定制 nilz/money 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nilz/money

最新稳定版本:1.10

Composer 安装命令:

composer require nilz/money

包简介

Implementation of money class

README 文档

README

A real world implementation of an extendable Money object using integers of smallest currency unit as calculation.

This library was created because other existing solutions had one or more of the following drawbacks:

  • missing extendability of Money class
  • dependency on fixed currency class
  • missing methods like format and convertTo currency
  • errors in implementation that caused to have rounding errors and missing cents in e.g. summing up prices
  • library not being maintained anymore

Free to use. Use it or leave it.

Examples

Create a money object:

use Nilz\Money\Money;
use Nilz\Money\Currency\ISO4217Currency;

$money = new Money(420, new ISO4217Currency('EUR'));

$money = Money::fromDefaultUnitAmount('4.20', 'EUR');

Get amount of money object:

//420
echo $money->getAmount();

//4.20
echo $money->getDefaultUnitAmount();

//4,20 €
echo $money->getFormattedAmount('de_DE');

Sum up two money objects:

$a = Money::fromDefaultUnitAmount('4.20', 'EUR');
$b = Money::fromDefaultUnitAmount('2.10', 'EUR');

$c = $a->add($b);

//6.30
echo $c->getAmount();

//4.20
echo $a->getAmount();

//2.10
echo $b->getAmount();

Other arithmetic examples:

$a = Money::fromDefaultUnitAmount('4.20', 'EUR');
$b = Money::fromDefaultUnitAmount('2.10', 'EUR');

$a->subtract($b);

$a->multiply(1.2);
$a->divide(1.2);

If you need other methods to perform calculations, you can easily extend the money object or put a pull request to extend it.

Use custom currency:

use Nilz\Money\Currency\Currency;

//alpha3 code, factor for smallest unit representation, decimal digits to round two
$money = new Money(420, new Currency('EUR', 100, 2));

You can also implement a custom currency object by implementing the CurrencyInterface.

统计信息

  • 总下载量: 14.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固