PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating measurements from integers and floats

In addition to integer data values, floating point types may be used, but "simple decimal fractions like 0.1 or 0.7 cannot be converted into their internal binary counterparts without a little loss of precision," sometimes giving surprising results. Also, do not compare two "float" type numbers for equality.

Example 608. Creation using integer and floating values

<?php
$measurement 
1234.7;
$unit = new Zend_Measure_Length((integer)$measurement,
                                
Zend_Measure_Length::STANDARD);
echo 
$unit;
// outputs '1234 m' (meters)

$unit = new Zend_Measure_Length($measurementZend_Measure_Length::STANDARD);
echo 
$unit;
// outputs '1234.7 m' (meters)

Zend Framework