承接 kazuto/laravel-money 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kazuto/laravel-money

Composer 安装命令:

composer require kazuto/laravel-money

包简介

Money Cast and Facade for Laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package adds a money cast and money facade to simplify storing financial values in the database by adding them as an integer column instead of float, double, or decimal, thus eliminating the possibility of floating point errors and resulting miscalculations.

Installation

You can install the package via composer:

composer require kazuto/laravel-money

You can publish and run the migrations with:

php artisan vendor:publish --provider="Kazuto\LaravelMoney\MoneyServiceProvider"

You can publish the config file with:

php artisan vendor:publish --provider="Kazuto\LaravelMoney\MoneyServiceProvider" --tag="money-config"

This is the contents of the published config file:

return [
  'locale_iso' => 'en_US'
];

Usage

// Base
Money::fromInt(524)->toInt();   // 524
Money::fromInt(524)->toFloat(); // 5.24
Money::fromInt(524)->toText();  // $5.24
Money::fromInt(524)->toArray();
// [
//   'value' => 524,
//   'formatted' => '$5.24',
//   'currency' => 'USD',
//   'symbol' => '$',
// ]

Money::fromFloat(5.24)->toInt();    // 524
Money::fromFloat(5.24)->toFloat();  // 5.24
Money::fromFloat(5.24)->toText();   // $5.24
Money::fromFloat(5.24)->toArray();
// [
//   'value' => 524,
//   'formatted' => '$5.24',
//   'currency' => 'USD',
//   'symbol' => '$',
// ] 


// Math

// add(Money|int|float)
Money::fromInt(524)->add(123);                    // 647
Money::fromInt(524)->add(1.23);                   // 647
Money::fromInt(524)->add(Money::fromFloat(1.23)); // 647

// substract(Money|int|float)
Money::fromInt(524)->substract(123);                    // 401
Money::fromInt(524)->substract(1.23);                   // 401
Money::fromInt(524)->substract(Money::fromFloat(1.23)); // 401

// multiply(int|float)
Money::fromInt(524)->multiply(2);     // 1048
Money::fromInt(524)->multiply(1.23);  // 645 (rounded from 644.52)

// divide(int|float)
Money::fromInt(524)->divide(2);       // 262
Money::fromInt(524)->divide(1.23);    // 426 (rounded from 426.01)

// Comparisons

// isEqualTo(Money|int|float)
Money::fromInt(524)->isEqualTo(524);                    // true
Money::fromInt(524)->isEqualTo(Money::fromFloat(5.24)); // true
Money::fromInt(524)->isEqualTo(1.23);                   // false
Money::fromInt(524)->isEqualTo(Money::fromInt(123));    // false

// isGreaterThan(Money|int|float)
Money::fromInt(524)->isGreaterThan(123);                    // true
Money::fromInt(524)->isGreaterThan(Money::fromFloat(1.23)); // true
Money::fromInt(524)->isGreaterThan(8.58);                   // false
Money::fromInt(524)->isGreaterThan(Money::fromInt(858));    // false
Money::fromInt(524)->isGreaterThan(524);                    // false
Money::fromInt(524)->isGreaterThan(Money::fromFloat(5.24)); // false

// isGreaterThanOrEqual(Money|int|float)
Money::fromInt(524)->isGreaterThanOrEqual(8.58);                   // false
Money::fromInt(524)->isGreaterThanOrEqual(524);                    // true
Money::fromInt(524)->isGreaterThanOrEqual(Money::fromFloat(5.24)); // true

// isLessThan(Money|int|float)
Money::fromInt(524)->isLessThan(8.58);                   // true
Money::fromInt(524)->isLessThan(Money::fromInt(858));    // true
Money::fromInt(524)->isLessThan(123);                    // false
Money::fromInt(524)->isLessThan(Money::fromFloat(1.23)); // false
Money::fromInt(524)->isLessThan(524);                    // false
Money::fromInt(524)->isLessThan(Money::fromFloat(5.24)); // false

// isLessThanOrEqual(Money|int|float)
Money::fromInt(524)->isLessThanOrEqual(2.24);                   // false
Money::fromInt(524)->isLessThanOrEqual(524);                    // true
Money::fromInt(524)->isLessThanOrEqual(Money::fromFloat(5.24)); // true

Testing

# Unit Tests
composer test:run

# Coverage
composer test:coverage

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固