1. Go to this page and download the library: Download worksome/number 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/ */
worksome / number example snippets
use Worksome\Number\Number;
$number = Number::of(100);
$number->mul(Number::of(5));
echo $number; // 500
use Illuminate\Database\Eloquent\Model;
use Worksome\Number\Casts\NumberFromCents;
use Worksome\Number\Casts\NumberFromDecimal;
use Worksome\Number\MonetaryAmount;
use Worksome\Number\Percentage;
use Worksome\Number\Number;
class Product extends Model
{
protected $casts = [
'a' => NumberFromCents::class,
'b' => NumberFromDecimal::class,
'c' => NumberFromDecimal::using(2, MonetaryAmount::class), // Cast to a specialised Number-class
'd' => NumberFromDecimal::using(2, Percentage::class), // Cast to a specialised Number-class
'e' => NumberFromDecimal::using(3), // Three decimal places - default is 2
];
}
// In Lighthouse (https://lighthouse-php.com)
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\DecimalTwoType());
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\PercentageType());
$typeRegistry->register(new \Worksome\Number\GraphQL\Scalars\StrictPercentageType());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.