kodeas / currency
为 Laravel 简单货币转换
1.0.5
2023-01-27 18:44 UTC
Requires
- php: ^8.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-09-09 11:40:55 UTC
README
为 Laravel 简单货币转换
此包旨在消除存储和检索货币中的歧义。目前,为了简单起见,该包周围的术语使用的是美元,然而,这并不妨碍任何人使用此包用于任何其他两位小数货币。
安装
您可以通过 composer 安装此包
composer require kodeas/currency
用法
MyModel extends Model { protected $casts = [ 'amount' => Kodeas\Currency\Casts\Currency::class ]; }
$currency = Kodeas\Currency\Currency::fromUsd(1); $model = MyModel::create([ 'amount' => $currency //100(cents) in database ]); $model->amount //Currency::class
初始化
$currency = Kodeas\Currency\Currency::fromUsd(1); $currency = Kodeas\Currency\Currency::fromCents(100);
方法
echo $currency; // "1.00" $currency->toUsd(); // "1" $currency->toCents(); // "100" $currency->toReadable(); // "1.00" $currency->toReadable('$'); // "$1.00" return response()->json(['currency' => $currency->toUsd()]); // {"currency": "1.00"}
致谢
许可证
MIT 许可证(MIT)。请参阅许可证文件以获取更多信息。
