Zend_Measure_Length::convertTo rounds the values. I would like 2520 meters
to be converted to 2.52 km, not 3 km.

I'm storing distances as meters in a mysql database. I'm using Zend_Db to
pull the values.

I create a new Zend_Measure_Length object with the distance value from mysql
typecast to an integer. For example:

//$meters = (int) $result['distance']; // (if pulling from db)

$meters = 2520; // For illustrative purposes

$distance = new Zend_Measure_Length($meters, Zend_Measure_Length::STANDARD);

echo $distance . '<br>'; // outputs 2,520 m

$distance->convertTo(Zend_Measure_Length::KILOMETER);

echo $distance . '<br>'; // outputs 3 km

echo $distance->toString(2); . '<br>'; // outputs 3.0 km

A var_dump of $distance immediately after calling convertTo shows the value
property with a value of 3.

I would like and had expected the output to be 2.52 km.

The same thing happens when converting seconds to minutes.

Where am I going wrong? Am I overlooking a configuration option somewhere?

Thanks,

Jason

Reply via email to