Created
February 23, 2018 00:28
-
-
Save David-Bascom/9369e3a2b26b4ef0db04270d60304a6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Nng\Whatever\ViewHelpers; | |
class PriceViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { | |
/** | |
* @var boolean | |
*/ | |
protected $escapeChildren = false; | |
/** | |
* @var boolean | |
*/ | |
protected $escapeOutput = false; | |
/** | |
* @param float $value | |
* @param string $currency | |
* @param string $zeros | |
*/ | |
public function render( $value = null, $currency = '€', $zeros = '–' ) { | |
if (!$value) $value = $this->renderChildren(); | |
$old_mon = setlocale(LC_MONETARY, "0"); | |
$old_num = setlocale(LC_NUMERIC, "0"); | |
setlocale(LC_MONETARY, 'de_DE'); | |
setlocale(LC_NUMERIC, 'de_DE'); | |
$locale = localeconv(); | |
$str = money_format('%!=#8.2i', $value); | |
setlocale(LC_MONETARY, $old_mon); | |
setlocale(LC_NUMERIC, $old_num); | |
if ($zeros !== null) { | |
if (substr($str, -3) == $locale['decimal_point'].'00') { | |
$str = substr($str, 0, strlen($str)-3).($zeros == '' ? '' : $locale['decimal_point']).$zeros; | |
} | |
} | |
return trim($currency.' '.$str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment