发布于 2015-10-07 09:50:57 | 127 次阅读 | 评论: 0 | 来源: 网络整理

26.3. Outputting measurements

Measurements can be output in a number of different ways.

Automatic output

Outputting values

Output with unit of measurement

Output as localized string

26.3.1. Automatic output

Zend_Measure supports outputting of strings automatically.

例 26.7. Automatic output

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure_Length($mystring,Zend_Measure_Length::STANDARD, $locale);

echo $unit;

                


[注意] Measurement output

Output can be achieved simply by using echo or print .

26.3.2. Outputting values

The value of a measurement can be output using getValue().

例 26.8. Output a value

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89 Meter";
$unit = new Zend_Measure_Length($mystring,Zend_Measure_Length::STANDARD, $locale);

echo $unit->getValue();

                


The getValue() method accepts an optional parameter 'round' which allows to define a precision for the generated output. The standard precision is '2'.

26.3.3. Output with unit of measurement

The function getType() returns the current unit of measurement.

例 26.9. Outputting units

$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure_Weight($mystring,Zend_Measure_Weight::POUND, $locale);

echo $unit->getType();

                


26.3.4. Output as localized string

Outputting a string in a format common in the users' country is usually desirable. For example, the measurement "1234567.8" would become "1.234.567,8" for Germany. This functionality will be supported in a future release.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务