rixafy/currency

货币CRUD操作,包含基本功能(列出、转换、更新等)

v2.0.2 2022-04-24 13:57 UTC

This package is auto-updated.

Last update: 2024-09-24 19:03:53 UTC


README

💱 使用Doctrine ORM在PHP中实现的CRUD模型

安装

composer require rixafy/currency

示例用法

与扩展一起工作的基本示例,您需要将服务注册到DI中或使用此集成到nette框架

转换

$eur = $this->currencyFacade->getByCode('EUR'); // returns Currency instance
$usd = $this->currencyFacade->getByCode('USD'); // returns Currency instance

$eur->convertFrom($usd, 100); // converts 100 USD to EUR, returns float
$eur->convertTo($usd, 100); // converts 100 EUR to USD, returns float

格式化

echo $this->currencyFacade->getByCode('USD')->formatToNumber(45.54); // returns 45.54
echo $this->currencyFacade->getByCode('EUR')->formatToNumber(45.54); // returns 45,54
echo $this->currencyFacade->getByCode('USD')->formatToString(45.54); // returns $45.54
echo $this->currencyFacade->getByCode('EUR')->formatToString(45.54); // returns 45,54 €

小数点、千位分隔符、符号和代码保存在数据库中(currency表)

重要

扩展需要Doctrine ORM和symfony\console进行货币导入。