18.3. Outputting measurements
Prev | Chapter 18. Zend_Measure | Next

## 18.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`

### 18.3.1. Automatic output

`Zend_Measure` supports outputting of strings automatically.

Example 18.7. Automatic output

    <?php
    require_once 'Zend/Measure/Length.php';

    $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` .

### 18.3.2. Outputting values

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

Example 18.8. Output a value

    <?php
    require_once 'Zend/Measure/Length.php';

    $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();
    ?>

### 18.3.3. Output with unit of measurement

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

Example 18.9. Outputting units

    <?php
    require_once 'Zend/Measure/Weight.php';

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

    echo $unit->getType();
    ?>

### 18.3.4. Output as localized string

Outputtig 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.

Prev | Up | Next
18.2. Creation of Measurements | Home | 18.4. Manipulating Measurements