Skip to content

Instantly share code, notes, and snippets.

@David-Bascom
Created February 23, 2018 00:28
Show Gist options
  • Save David-Bascom/9369e3a2b26b4ef0db04270d60304a6d to your computer and use it in GitHub Desktop.
Save David-Bascom/9369e3a2b26b4ef0db04270d60304a6d to your computer and use it in GitHub Desktop.
<?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.'&nbsp;'.$str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment