Now that the busy holiday season is over, would someone mind taking a look at my patch?

Thanks,
Cale

On 12/24/2009 10:34 PM, Cale Scholl (JIRA) wrote:
      [ 
https://issues.apache.org/jira/browse/TRINIDAD-1666?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Cale Scholl updated TRINIDAD-1666:
----------------------------------

     Status: Patch Available  (was: Open)

convertNumber without maxfractiondigits specified limits digits to 3
--------------------------------------------------------------------

                 Key: TRINIDAD-1666
                 URL: https://issues.apache.org/jira/browse/TRINIDAD-1666
             Project: MyFaces Trinidad
          Issue Type: Bug
          Components: Components
    Affects Versions:  1.2.12-core
            Reporter: Cale Scholl
            Priority: Minor
         Attachments: fractionDigits_1.2.12.2.patch, fractionDigits_trunk.patch


ISSUE:
----------
Given a default convertNumber e.g.<af:convertNumber id="cn1" type="number"/>:
Enter 1.23456789. Press Submit. You will see that the number is rounded to 
1.235, only 3 fractional digits.
FIX:
-----
1. Server-side converter: If maximumFractionDigits isn't explicitly specified, 
then set it to the highest possible value, so that no fraction digits are 
truncated.
trinidad-api\src\main\java\org\apache\myfaces\trinidad\convert\NumberConverter 
_setFormatProperties:
   if (isMaximumFractionDigitsSet())
   {
     formatter.setMaximumFractionDigits(getMaxFractionDigits());
   }
   else
   {
     // Override the default java behavior. The default number formatter
     // created via NumberFormat.getNumberInstance(locale) has a
     // maxFractionDigits of 3. I don't see why this behavior would be
     // desired; the fraction digits shouldn't be truncated unless that
     // behavior is explicitly requested.
     // According to the javadoc for
     // java.text.DecimalFormat.setMaximumFractionDigits,
     // the fraction digit count is limited to 340.
     formatter.setMaximumFractionDigits(340);
   }
2. Client-side converter: Don't set a default value for maxFractionDigits.
trinidad-impl\src\main\javascript\META-INF\adf\jsLibs\NumberFormat.js
function TrNumberFormat:
   // The default behavior of convertNumber with respect to number of
   // fractional digits should be the same as the implicit conversion to a
   // number. That is also the behavior that is documented in the javadoc for
   // javax.faces.convert.NumberConverter
   //this._maxFractionDigits = 3;
3. Client-side converter: maxFractionDigits should only be applied during 
formatting (getAsString), not during parsing (getAsObject).
trinidad-impl\src\main\javascript\META-INF\adf\jsLibs\NumberConverter.js
TrNumberConverter.prototype.getAsObject:
   // We shouldn't be losing presicion here when converting to object;
   // _maxFractionDigits should only be applied during formatting when we
   // convert the number to a string.
   //parsedValue = 
parseFloat(parsedValue.toFixed(this._numberFormat.getMaximumFractionDigits()));
4. Client-side converter: If maxFractionDigits is undefined, then don't 
truncate any fraction digits.
TrNumberConverter.prototype.getAsString:
   else
   {
     // _maxFractionDigits should only be applied if explicitly specified.
     var maxFractionDigits = this._numberFormat.getMaximumFractionDigits();
     return (maxFractionDigits === undefined) ?
       this._numberFormat.format(parseFloat(number))
         :
       this._numberFormat.format(parseFloat(number.toFixed(maxFractionDigits)));
   }

Reply via email to