<?php  namespace App\Services\Orders;  use Exception; use App\Exceptions\NotANumberException; use App\Exceptions\UnknownMathOperationException;  class MathMoneyOperations { 	public static function calculate(string|float|int $number1, string|float|int $number2, string $operation): string 	{ 		if (!is_numeric($number1) && !is_numeric($number2)) { 			throw new NotANumberException; 		}  		$removeUnnecessaryZeros = function (string $total): string { 			if (strpos($total, '.')) { 				$total = rtrim($total, '0'); 				// $total = rtrim($total, '.');  				if ($total[strlen($total) - 2] == '.') { 					$total .= '0'; 				} elseif ($total[strlen($total) - 1] == '.') { 					$total .= '00'; 				}  				return $total; 			}  			return $total .= '.00'; 		};  		bcscale(4);  		switch ($operation) { 			case '+': 				return $removeUnnecessaryZeros(max(bcadd($number1, $number2), '0'));  			case '-': 				return $removeUnnecessaryZeros(max(bcsub($number1, $number2), '0'));  			case '*': 				return $removeUnnecessaryZeros(max(bcmul($number1, $number2), '0'));  			case '/':  				if ($number2 == 0 || ($number2 == '0.0') || $number2 == '0.00') { 					throw new Exception('cant divide with zero'); 				}  				return $removeUnnecessaryZeros(max(bcdiv($number1, $number2), '0'));  			default:  				throw new UnknownMathOperationException; 		} 	} }