Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.1

Request #21072 Allow calculateTotalsFor() to parse formatted numbers
Submitted: 2016-05-31 19:11 UTC
From: bmcdanel Assigned:
Status: Open Package: Console_Table (version 1.3.0)
PHP Version: Irrelevant OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2016-05-31 19:11 UTC] bmcdanel (Bret McDanel)
Description: ------------ When a filter is applied it will be processed before calculateTotalsFor() is processed. This can be a good thing as numbers can be altered during the format stage. If calculateTotalsFor() was processed first then 2+2=5 could happen for large values of 2 and a formatting stripping the fractional part (eg float to int). A simple method that requires you to specify or use a default can be found at https://gist.github.com/msng/1504235 calculateTotalsFor() could take additional optional parameters that would specify the additional data or it could be set somewhere else. Below I try to explain the challenge to unformatting a number without knowing what the integral separator and decimal separator are. I think that it will largely push towards having the user just declare it based on the data they presumably know the format for. There are 3 main categories for numbers. Sign, integral part, decimal part. Some examples of different formatting styles can be found at https://en.wikipedia.org/wiki/Decimal_mark#Examples_of_use SIGN This can be a variety of things. +123 = 123 123 = 123 -123 = -123 123- = -123 (123) = -123 %r123 = -123 (color formatting, red) FRACTIONAL PART This is often one of two characters a comma or a full stop (period). There is never more than one fractional separator however with an integer it may not be present. INTEGRAL PART This can be one of several characters. a comma, space, full stop, ' (in a couple styles). There may be more I am unaware of. It may or may not be present, and groupings may be 2, 3 or 4 digits. It will always be left of the fractional separator except when it is not (eg right to left languages like those in the Middle East). You cannot programmatically parse all numbers. 1.000 could be 1000 or it could be 1 unless you know the fractional separator and the integral separator ahead of time. You cannot rely on the system locale as it may be serving data intended for someone using a different locale SCIENTIFIC NOTATION and other numerical schemes outside the scope for this, although it could be added easily enough. My patch incorporates the trivial fix for https://pear.php.net/bugs/bug.php?id=21070

Comments

 [2016-05-31 19:13 UTC] bmcdanel (Bret McDanel)
 [2016-05-31 19:15 UTC] bmcdanel (Bret McDanel)
I should have said "also incorporates the trivial fix ..." as both are in there.
 [2016-06-01 01:50 UTC] bmcdanel (Bret McDanel)