voteMike/money

一个处理货币(值和货币的组合)的类

1.2.0 2017-11-30 19:49 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:16:57 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License composer.lock StyleCI

传递一个金额和货币到Money对象以创建一个不可变对象。使用对象执行操作。处理不同货币的不同单位和舍入。格式化货币以供显示。请使用GitHub提出任何问题和建议任何改进。

安装

通过Composer

$ composer require votemike/money

用法

$money = new Money(99.999999, 'GBP');
$add = $money->add(new Money(20, 'GBP'));
$sub = $money->sub(new Money(20, 'GBP'));
$multiply = $money->multiply(3);
$divide = $money->divide(3);
$abs = $money->abs();
$inv = $money->inv();
$percentage = $money->percentage(20);
$round = $money->round();
list($first, $second, $third) = $money->split(20, 33.33);

$money = new Money(99.50, 'JPY');
$money->format(); //¥100
$money->formatWithSign(); //+¥100
$money->getAmount(); //99.50
$money->getCurrency(); //JPY
$money->getRoundedAmount(); //100

$money = new Money(9500, 'USD');
$money->formatShorthand(); //$10k

$money = new Money(-9.500, 'USD');
$money->formatForAccounting(); //(9.50)

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件