PHP code example of ramazancetinkaya / percentage-calculator

1. Go to this page and download the library: Download ramazancetinkaya/percentage-calculator 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/ */

    

ramazancetinkaya / percentage-calculator example snippets




use ramazancetinkaya\PercentageCalculator;

$calculator = new PercentageCalculator();

try {
    // Calculate percentage
    $result = $calculator->calculatePercentage(250, 20);
    echo "20% of 250 is: " . $result . "\n";

    // Calculate percentage change
    $change = $calculator->calculatePercentageChange(100, 75);
    echo "Percentage change from 100 to 75 is: " . $change . "%\n";

    // Increase by percentage
    $increase = $calculator->increaseByPercentage(50, 25);
    echo "50 increased by 25% is: " . $increase . "\n";

    // Decrease by percentage
    $decrease = $calculator->decreaseByPercentage(80, 10);
    echo "80 decreased by 10% is: " . $decrease . "\n";
} catch (InvalidArgumentException $e) {
    echo "Error: " . $e->getMessage();
}