1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.measure.output">
<title>Outputting measurements</title>
<para>
Measurements can be output in a number of different ways.
</para>
<para>
<link linkend="zend.measure.output.auto">Automatic output</link>
</para>
<para>
<link linkend="zend.measure.output.value">Outputting values</link>
</para>
<para>
<link linkend="zend.measure.output.unit">Output with unit of measurement</link>
</para>
<para>
<link linkend="zend.measure.output.unit">Output as localized string</link>
</para>
<sect2 id="zend.measure.output.auto">
<title>Automatic output</title>
<para>
<classname>Zend_Measure</classname> supports outputting of strings automatically.
<example id="zend.measure.output.auto.example-1">
<title>Automatic output</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure_Length($mystring,
Zend_Measure_Length::STANDARD,
$locale);
echo $unit;
]]></programlisting>
</example>
</para>
<note>
<title>Measurement output</title>
<para>
Output can be achieved simply by using
<ulink url="http://php.net/echo">echo</ulink> or
<ulink url="http://php.net/print">print</ulink>.
</para>
</note>
</sect2>
<sect2 id="zend.measure.output.value">
<title>Outputting values</title>
<para>
The value of a measurement can be output using <methodname>getValue()</methodname>.
<example id="zend.measure.output.value.example-1">
<title>Output a value</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure_Length($mystring,
Zend_Measure_Length::STANDARD,
$locale);
echo $unit->getValue();
]]></programlisting>
</example>
</para>
<para>
The <methodname>getValue()</methodname> method accepts an optional parameter
<property>round</property> which allows to define a precision for the generated
output. The standard precision is '2'.
</para>
</sect2>
<sect2 id="zend.measure.output.unit">
<title>Output with unit of measurement</title>
<para>
The function <methodname>getType()</methodname> returns the current unit of measurement.
<example id="zend.measure.output.unit.example-1">
<title>Outputting units</title>
<programlisting language="php"><![CDATA[
$locale = new Zend_Locale('de');
$mystring = "1.234.567,89";
$unit = new Zend_Measure_Weight($mystring,
Zend_Measure_Weight::POUND,
$locale);
echo $unit->getType();
]]></programlisting>
</example>
</para>
</sect2>
<sect2 id="zend.measure.output.localized">
<title>Output as localized string</title>
<para>
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.
</para>
</sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
|