定制 superbalist/php-money 二次开发

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

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

superbalist/php-money

最新稳定版本:2.0.0

Composer 安装命令:

composer require superbalist/php-money

包简介

A money and currency library for handling arbitrary-precision arithmetic

README 文档

README

A money and currency library for handling arbitrary-precision arithmetic

Author Build Status StyleCI Software License Packagist Version Total Downloads

Installation

composer require superbalist/php-money

Usage

use Superbalist\Money\CurrencyConversionServiceProvider;
use Superbalist\Money\CurrencyFactory;
use Superbalist\Money\Money;
use Superbalist\Money\OpenExchangeRatesCurrencyConversionService;

// set default currency conversion service
// this is optional, and is only required if you're going to be converting between currencies
$service = new OpenExchangeRatesCurrencyConversionService('[[insert app id here]]');
CurrencyConversionServiceProvider::setCurrencyConversionService($service);

// set default currency
CurrencyFactory::setDefault('ZAR');

// a money object can be constructed very loosely
$a = new Money(150);
$a = new Money('150'); // recommended
$a = new Money('150.00');
$a = new Money(150.00); // not recommended, as we're trying to avoid using floating points
$a = new Money('150', CurrencyFactory::make('USD'));

// basic operations on numbers
$a = new Money('150.55');
$b = new Money('99.45');
$c = $a->add($b); // 250

$a = new Money('300.00');
$b = new Money('2');
$c = $a->divide($b); // 150

// comparing numbers
$a = new Money('0.33');
$b = new Money('0.33');
$c = $a->equals($b); // true
$c = $a->isGreaterThan($b); // false
$c = $a->isGreaterThanOrEqualTo($b); // true
$c = $a->isLessThan($b); // false

// convert a monetary value from currency A to currency B
$a = new Money('100', CurrencyFactory::make('ZAR'));
$b = $a->toCurrency(CurrencyFactory::make('USD'));

// format a number for display
$a = new Money('123.9999');
echo $a->format(); // 123.99
echo $a->display(); // R123.99

// handling value added tax
$a = new Money('100');
$rate = '0.14';
$b = $a->calculateVat($rate); // 14
$c = $a->add($b); // 114
$d = $c->calculateNetVatAmount($rate); // 100

// min & max
$a = new Money('100');
$b = new Money('101');
$c = $a->max($b); // 101
$d = $a->min($b); // 100

// ...see classes for full list of methods

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 40
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-01