<?php
 namespace App\Utils; class PriceFormat { static public function format(float|string|null $amount, ?string $currency=null, $hideCurrency=false) :string { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); if ($currency) { $decimals = \App\Config\CurrencyDecimals::getCurrencyDecimals($currency); if ($decimals===null) { $decimals = $CFG['localization']['maxDecimalsOnPrices']; } } else { $decimals = $CFG['localization']['maxDecimalsOnPrices']; } if ($CFG['localization']['numberFormat']=='eu') { $decimalsSep = ','; $thousandsSep = '.'; } elseif ($CFG['localization']['numberFormat']=='us') { $decimalsSep = '.'; $thousandsSep = ','; } else { $decimalsSep = '.'; $thousandsSep = ''; } $formattedAmount = number_format((float)$amount, $decimals, $decimalsSep, $thousandsSep); if ($hideCurrency) { return $formattedAmount; } else { if ($CFG['localization']['priceFormat']=='currencyFirst') { return trim($currency.' '.$formattedAmount); } else { return trim($formattedAmount.' '.$currency); } } } }