/** * Get the unit from the form. If it's defined and different than the * display unit, convert the value and set it back into this control's value. * Then, format with proper number of digits. * * Do not call this method more than once! */ protected function convert() { $user = Transaction::getInstance()->getUser(); if ($this->getValue() !== null && Zend_Locale_Format::isNumber($this->getValue(), array("locale" => $user->getLocale()))) { $form = $this->getForm(); // Get the 'hidden' value, which indicates the unit of the current value. $unit = $form->getValue($this->getUnitFieldName()); // If the unit is different, convert if ($unit && $unit != $this->displayUnit) { $measure = MeasureUtils::newMeasure($unit, $this->getValue(), $user->getLocale()); $unitInfo = MeasureUtils::getUnitInfo($this->displayUnit); $measure->setType($unitInfo['constantName']); // Sets the new value without rounding and without formatting $this->setValue($measure->getValue(-1, $user->getLocale())); } $format = Formatter::getInstance(); // Format and round the value $this->setValue($format->number($format->getNumber($this->getValue()), $this->decimalDigits)); } }
/** * @covers MeasureUtils::getUnitInfo * @todo Implement testGetUnitInfo(). */ public function testGetUnitInfo() { $actual = \MeasureUtils::getUnitInfo('Zend_Measure_Temperature::CELSIUS'); $excepted = array('className' => 'Zend_Measure_Temperature', 'constantName' => 'CELSIUS'); $this->assertEquals($excepted, $actual); }