PHP code example of roboticsexpert / laravel-decimal

1. Go to this page and download the library: Download roboticsexpert/laravel-decimal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roboticsexpert / laravel-decimal example snippets


composer 
 

use Roboticsexpert\LaravelDecimal\DecimalCast;


class YourModel extend Model {
    public $cast=[
        'your_field' => DecimalCast::class,
    ];

}
 

$value = new \Decimal\Decimal('12345.131123123123123');
$model=new YourModel();
$model->your_filed=$value;
... (other stuff)
$model->save();

 


$model=YourModel::first();
$model->your_filed // \Decimal\Decimal "12345.131123123123123"

//add 123 to your field
$model->your_field=$model->your_field->add('123');

//sub 123 from your field
$model->your_field=$model->your_field->sub('123');

// check php-decimal package for other methods you can use!