PhpRiot
Follow phpriot on Twitter
Sponsored Link
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

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