Forums / Developer / ezfloat - rounding up number issue

ezfloat - rounding up number issue

Author Message

steve walker

Friday 27 July 2007 6:35:53 am

Hi there,

We have an issue with ezfloat in conjunction the l10n operator. It seems its covered to an extent here:

http://issues.ez.no/3755

However, I havent been abl to fix our issue - which is that we are storing financial figures in a system - and when the numbers start going over 1,000,000 the number start getting rounded to the nearest 100. The full operator is:

|l10n(number)

How can I change the operator so that it just displays the exact number without any rounding, preferably with 2 decimal places?

Many thanks, Steve.

http://www.oneworldmarket.co.uk

Felipe Jaramillo

Wednesday 01 August 2007 10:15:03 am

Hi Steve,

We have now reproduced, investigated and solved the rounding issue. It is related to the default mysql database structure, where numbers (float) are 4 bytes and rounded after 6 figures by default.

We have successfully changed this to allow 15 figure numbers before rounding them. After doing the change in our test servers, it does not disrupt the existing data.

In my opinion, people should be warned about this inaccuracy as it affects any default installation and there is no alternative datatype for accurately storing long numbers other than TextLine.

This inaccuracy is present in the existing numbers 6 figure numbers and up as they are rounded. Eg. 1234567 is stored as 1234570.

To fix:

Increase length of FLOAT to 25 (8 bytes) in “data_float” field in table “ezcontentobject_attribute”, which will effectively make it a DOUBLE 8byte number, accurate to 15 figure numbers.

More info in:
http://dev.mysql.com/doc/refman/4.1/en/choosing-types.html
http://dev.mysql.com/doc/refman/4.1/en/storage-requirements.html
http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html

Felipe Jaramillo
eZ Certified Extension Developer
http://www.aplyca.com | Bogotá, Colombia