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
Requires
- php: >=7.3
- illuminate/database: ^5|^6|^7|^8
Requires (Dev)
README
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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
Released under the MIT license