Zend Framework

Precision and number_format seems to be broken

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.1
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Locale
  • Labels:
    None

Description

I encountered a bug when trying to use
$number = Zend_Locale_Format::toNumber('26.7857142857', array('precision' => 2, 'locale' => 'sv_SE'); Instead of 26,79 it returned 26,78.

I then tried with the examples given in the reference guide and they also returned wrong results.

$locale = new Zend_Locale('de_AT');
$number = Zend_Locale_Format::getNumber('13.524,678', array('precision' => 1, 'locale' => $locale));
print $number; // will return 13524.7

In fact this code will return 13524.6

$locale = new Zend_Locale('de_AT');
$number = Zend_Locale_Format::getNumber('13.524,678', array('number_format' => '#.00', 'locale' => $locale));
print $number; // will return 13524.67

This is currently returning a value of 13524.678

Issue Links

Activity

Hide
Thomas Weidner added a comment -

Duplicate of ZF-3473

Show
Thomas Weidner added a comment - Duplicate of ZF-3473
Hide
Thomas Weidner added a comment -

Fixed with r13990

Show
Thomas Weidner added a comment - Fixed with r13990
Hide
Michal Lasak added a comment -

I've noticed when bcmath extension is enabled the problem reoccurs.

Example from manual
$number = Zend_Locale_Format::toNumber(13547.3678,
                                       array('precision' => 2,
                                             'locale' => $locale));

returns 13547.36 with bcmath enabled. Zend Server 5.0, ZF 1.10.2, PHP 5.2.12, Windows 7.

Show
Michal Lasak added a comment - I've noticed when bcmath extension is enabled the problem reoccurs.
Example from manual
$number = Zend_Locale_Format::toNumber(13547.3678,
                                       array('precision' => 2,
                                             'locale' => $locale));
returns 13547.36 with bcmath enabled. Zend Server 5.0, ZF 1.10.2, PHP 5.2.12, Windows 7.

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: