niclashedam/eloquent-round

此包已被废弃,不再维护。未建议替代包。

Laravel Eloquent 中小数/浮点/双精度数的自动四舍五入

1.3.4 2022-06-22 11:48 UTC

This package is auto-updated.

Last update: 2022-06-22 11:48:43 UTC


README

Build Status Coverage Status FOSSA Status

此包可以在 eloquent 模型设置属性时自动将所有给定的小数值四舍五入。当使用 MySQL 数据库时,这尤其有用,因为您可以知道正确的值被写入数据库。

安装

使用 composer 安装

composer require niclashedam/eloquent-round

使用

使用 RoundsDecimals 特性。

use NiclasHedam\EloquentRound\RoundsDecimals;

class Model extends \Illuminate\Database\Eloquent\Model
{
    use RoundsDecimals;

    public $rounds = [
        'decimal' => 2,
        'preciseDecimal' => 4,
    ];
}
$model->decimal = 1.675;
echo $model->decimal; //1.68

贡献

  1. 分支它!
  2. 创建您的功能分支:git checkout -b my-new-feature
  3. 提交您的更改:git commit -am '添加一些功能'
  4. 推送到分支:git push origin my-new-feature
  5. 提交 pull request :D

许可证

在 MIT 许可下发布

FOSSA Status