1. Go to this page and download the library: Download prestashop/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/ */
prestashop / decimal example snippets
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\Decimal\Operation\Rounding;
echo (new DecimalNumber('0.1'))
->plus(new DecimalNumber('0.7'))
->times(new DecimalNumber('10'))
->round(0, Rounding::ROUND_FLOOR)
// echoes '8'
public __construct ( string $number [, int $exponent = null ] ): DecimalNumber
public DecimalNumber::plus ( DecimalNumber $addend ): DecimalNumber
$a = new PrestaShop\Decimal\DecimalNumber('123.456');
$b = new PrestaShop\Decimal\DecimalNumber('654.321');
echo $a->plus($b); // echoes '777.777'
public DecimalNumber::minus ( DecimalNumber $subtrahend ): DecimalNumber
$a = new PrestaShop\Decimal\DecimalNumber('777.777');
$b = new PrestaShop\Decimal\DecimalNumber('654.321');
echo $a->minus($b); // echoes '123.456'
public DecimalNumber::times ( DecimalNumber $factor ): DecimalNumber
$a = new PrestaShop\Decimal\DecimalNumber('777.777');
$b = new PrestaShop\Decimal\DecimalNumber('654.321');
echo $a->times($b); // echoes '508915.824417'
public DecimalNumber::dividedBy ( DecimalNumber $divisor [, int $precision = Operation\Division::DEFAULT_PRECISION ] )
public DecimalNumber::toMagnitude ( int $exponent ): DecimalNumber
$a = new PrestaShop\Decimal\DecimalNumber('123.456789');
// shift 3 digits to the left
$a->toMagnitude(-3); // 0.123456789
// shift 3 digits to the right
$a->toMagnitude(3); // 123456.789
$number = new PrestaShop\Decimal\DecimalNumber('123.45');
$number->getIntegerPart(); // '123'
$number->getFractionalPart(); // '45'
$number->getPrecision(); // '2' (number of decimals)
$number->getSign(); // '' ('-' if the number was negative)
$number->getExponent(); // '2' (always positive)
$number->getCoefficient(); // '123456'
$number->isPositive(); // true
$number->isNegative(); // false
$number->invert(); // new Decimal\DecimalNumber('-123.45')
php
// create a number from string
$number = new PrestaShop\Decimal\DecimalNumber('123.456');
echo $number; // echoes '123.456'