protected function makeUserValue()
 {
     $value = false;
     if ($this->m_outformat && $this->m_outformat != '-' && $this->m_outformat != '-n' && $this->m_outformat != '-u') {
         // first try given output unit
         $printunit = SMWNumberValue::normalizeUnit($this->m_outformat);
         $this->m_unitin = $this->getUnitID($printunit);
         switch ($this->m_unitin) {
             case 'K':
                 $value = $this->m_dataitem->getNumber();
                 break;
             case '°C':
                 $value = $this->m_dataitem->getNumber() - 273.15;
                 break;
             case '°F':
                 $value = ($this->m_dataitem->getNumber() - 273.15) * 1.8 + 32;
                 break;
             case '°R':
                 $value = $this->m_dataitem->getNumber() * 1.8;
                 break;
                 // default: unit not supported
         }
     }
     if ($value === false) {
         // no valid output unit requested
         $value = $this->m_dataitem->getNumber();
         $this->m_unitin = 'K';
         $printunit = 'K';
     }
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? NumberFormatter::getInstance()->getLocalizedFormattedNumber($value, $this->getPrecision()) : NumberFormatter::getInstance()->getUnformattedNumberByPrecision($value, $this->getPrecision());
     }
     if ($printunit !== '' && $this->m_outformat != '-n') {
         // -n is the format for displaying the number only
         if ($this->m_outformat != '-u') {
             $this->m_caption .= $this->m_outformat != '-' ? ' ' : ' ';
         }
         $this->m_caption .= $printunit;
     }
 }
 /**
  * This method is used when no user input was given to find the best
  * values for m_unitin and m_caption. After conversion,
  * these fields will look as if they were generated from user input,
  * and convertToMainUnit() will have been called (if not, it would be
  * blocked by the presence of m_unitin).
  *
  * Overwritten by subclasses that support units.
  */
 protected function makeUserValue()
 {
     $this->m_caption = '';
     $number = $this->m_dataitem->getNumber();
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? NumberFormatter::getInstance()->getLocalizedFormattedNumber($number, $this->getPrecision()) : NumberFormatter::getInstance()->getUnformattedNumberByPrecision($number, $this->getPrecision());
     }
     // no unit ever, so nothing to do about this
     $this->m_unitin = '';
 }
예제 #3
0
 /**
  * This method is used when no user input was given to find the best
  * values for m_unitin and m_caption. After conversion,
  * these fields will look as if they were generated from user input,
  * and convertToMainUnit() will have been called (if not, it would be
  * blocked by the presence of m_unitin).
  *
  * Overwritten by subclasses that support units.
  */
 protected function makeUserValue()
 {
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? NumberFormatter::getInstance()->formatNumberToLocalizedText($this->m_dataitem->getNumber()) : $this->m_dataitem->getNumber();
     }
     // no unit ever, so nothing to do about this
     $this->m_unitin = '';
 }
/**
 * @deprecated since 2.1, use NumberFormatter instead
 */
function smwfNumberFormat($value, $decplaces = 3)
{
    return NumberFormatter::getInstance()->getLocalizedFormattedNumber($value, $decplaces);
}
예제 #5
0
 protected function makeUserValue()
 {
     $printunit = false;
     // the normalised string of a known unit to use for printouts
     // Check if a known unit is given as outputformat:
     if ($this->m_outformat && $this->m_outformat != '-' && $this->m_outformat != '-n' && $this->m_outformat != '-u') {
         // first try given output unit
         $wantedunit = SMWNumberValue::normalizeUnit($this->m_outformat);
         if (array_key_exists($wantedunit, $this->m_unitids)) {
             $printunit = $wantedunit;
         }
     }
     // Alternatively, try to use the main display unit as a default:
     if ($printunit === false) {
         $this->initDisplayData();
         if (count($this->m_displayunits) > 0) {
             $printunit = reset($this->m_displayunits);
         }
     }
     // Finally, fall back to main unit:
     if ($printunit === false) {
         $printunit = $this->getUnit();
     }
     $this->m_unitin = $this->m_unitids[$printunit];
     $this->m_unitvalues = false;
     // this array depends on m_unitin if displayunits were used, better invalidate it here
     $value = $this->m_dataitem->getNumber() * $this->m_unitfactors[$this->m_unitin];
     $this->m_caption = '';
     if ($this->m_outformat != '-u') {
         // -u is the format for displaying the unit only
         $this->m_caption .= $this->m_outformat != '-' && $this->m_outformat != '-n' ? NumberFormatter::getInstance()->formatNumberToLocalizedText($value) : $value;
     }
     if ($printunit !== '' && $this->m_outformat != '-n') {
         // -n is the format for displaying the number only
         if ($this->m_outformat != '-u') {
             $this->m_caption .= $this->m_outformat != '-' ? ' ' : ' ';
         }
         $this->m_caption .= $printunit;
     }
 }
 /**
  * @dataProvider unformattedNumberByPrecisionProvider
  */
 public function testGetUnformattedNumberByPrecision($maxNonExpNumber, $number, $precision, $expected)
 {
     $instance = new NumberFormatter($maxNonExpNumber);
     $this->assertEquals($expected, $instance->getUnformattedNumberByPrecision($number, $precision));
 }
 /**
  * @dataProvider numberProvider
  */
 public function testFormatNumberToLocalizedText($maxNonExpNumber, $number, $expected)
 {
     $instance = new NumberFormatter($maxNonExpNumber);
     $this->assertEquals($expected, $instance->formatNumberToLocalizedText($number));
 }
/**
 * @deprecated since 2.1, use NumberFormatter instead
 */
function smwfNumberFormat($value, $decplaces = 3)
{
    return NumberFormatter::getInstance()->formatNumberToLocalizedText($value, $decplaces);
}