/**
  * Renders the localized number, be it currency or decimal, or percentage.
  * If the culture is not specified, the default application
  * culture will be used.
  * This method overrides parent's implementation.
  */
 protected function renderBody()
 {
     $app = $this->Application->getGlobalization();
     //initialized the default class wide formatter
     if (is_null(self::$formatter)) {
         self::$formatter = new NumberFormat($app->Culture);
     }
     $culture = $this->getCulture();
     $pattern = $this->getPattern();
     $type = $this->getType();
     if (empty($pattern)) {
         $pattern = $type;
     }
     $value = $this->getValue();
     if (strlen($value) == 0) {
         $value = parent::renderBody();
     }
     //return the specific cultural formatted number
     if (!empty($culture) && $app->Culture != $culture) {
         $formatter = new NumberFormat($culture);
         return $formatter->format($value, $pattern, $this->getCurrency());
     }
     //return the application wide culture formatted number.
     return self::$formatter->format($value, $pattern, $this->getCurrency());
 }
예제 #2
0
 /**
  * Formats the localized number, be it currency or decimal, or percentage.
  * If the culture is not specified, the default application
  * culture will be used.
  * @return string formatted number
  */
 protected function getFormattedValue()
 {
     $value = $this->getValue();
     $defaultText = $this->getDefaultText();
     if (empty($value) && !empty($defaultText)) {
         return $this->getDefaultText();
     }
     $app = $this->getApplication()->getGlobalization();
     //initialized the default class wide formatter
     if (self::$formatter === null) {
         self::$formatter = new NumberFormat($app->getCulture());
     }
     $pattern = strlen($this->getPattern()) > 0 ? $this->getPattern() : $this->getType();
     $culture = $this->getCulture();
     //return the specific cultural formatted number
     if (!empty($culture) && $app->getCulture() != $culture) {
         $formatter = new NumberFormat($culture);
         return $formatter->format($this->getValue(), $pattern, $this->getCurrency(), $this->getCharset());
     }
     //return the application wide culture formatted number.
     return self::$formatter->format($this->getValue(), $pattern, $this->getCurrency(), $this->getCharset());
 }