niclashedam/eloquent-round

This package is abandoned and no longer maintained. No replacement package was suggested.

Automatic rounding of decimals/floats/doubles in 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

This package automatically rounds all given decimal values when setting the attribute in a eloquent model. This is especially great, when you use a MySQL database, so that you know the right value is written to the database.

Installation

Install it using composer

composer require niclashedam/eloquent-round

Usage

Use the RoundsDecimals trait.

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

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

Released under the MIT license

FOSSA Status