My favorites | Sign in
Project Logo
                
Details: Show all Hide all

Earlier this year

  • Sep 12, 2009
    printf-as3-rev19.zip (Printf rev 19, src, docs and test suite.) file uploaded by debert   -  
    Labels: Featured
    Labels: Featured
  • Sep 12, 2009
    issue 4 (SUBS_RE is buggy) Status changed by debert   -   Hi Helmut. Sorry for taking this long to get back. Well turns out that the solution was much simpler, instead of rellying on a buggy toPrecision implementation, we can just defer to the the native Number.toFixedPrecision. Fixed in rev 18. I've also included a regression test for this issue. Thanks for the detailed write up. Cheers Arthur Debert
    Status: Fixed
    Hi Helmut. Sorry for taking this long to get back. Well turns out that the solution was much simpler, instead of rellying on a buggy toPrecision implementation, we can just defer to the the native Number.toFixedPrecision. Fixed in rev 18. I've also included a regression test for this issue. Thanks for the detailed write up. Cheers Arthur Debert
    Status: Fixed
  • Sep 12, 2009
    r19 (Moved test suite to test dir, so that regular users can fetc...) committed by debert   -   Moved test suite to test dir, so that regular users can fetch only the main source
    Moved test suite to test dir, so that regular users can fetch only the main source
  • Sep 12, 2009
    r18 (Refactored toPrecion to use the Number.toFixedPrecision, fix...) committed by debert   -   Refactored toPrecion to use the Number.toFixedPrecision, fixes issue #4 , thanks Helmut Messerer
    Refactored toPrecion to use the Number.toFixedPrecision, fixes issue #4 , thanks Helmut Messerer
  • Sep 12, 2009
    r17 (Cleanup and changes to the unit test project.) committed by debert   -   Cleanup and changes to the unit test project.
    Cleanup and changes to the unit test project.
  • Jul 11, 2009
    issue 4 (SUBS_RE is buggy) commented on by helmut.messerer   -   unfortunately Nate Cook's code has a bug too... my final version for truncateNumber() now looks like this: function truncateNumber(raw : Number, decimals :int =2) : String { // Nate Cook's brainchild var intPortion:String = ''; var decPortion:String = ''; var value :String = String(raw); if (value.indexOf('.') == -1) { intPortion = (Math.abs(Number(value))).toString(); decPortion = "0"; } else { intPortion = (Math.abs(Number(value.substring(0,value.indexOf('.'))))).toString(); decPortion = value.substr(value.indexOf('.') + 1); } // create decimal portion if (Number(decPortion) == 0) { decPortion = ''; while (decPortion.length < decimals) decPortion += '0'; } else { if (decPortion.length > decimals) { var dec:Number = Math.round(Math.pow(10, decimals) * Number('0.' + decPortion)); if(((String(dec)).length > decimals) && (dec != 0)) { decPortion = '0'; intPortion = ((Math.abs(Number(intPortion)) + 1) * (Number(intPortion) >= 0 ? 1 : -1)).toString(); } else { decPortion = String(dec); // bugfix here: while(decPortion.length < decimals) decPortion = '0' + decPortion; } } if (decPortion.length < decimals) { decPortion = new String(decPortion); while(decPortion.length < decimals) decPortion += '0'; } } // combine pieces if(decimals == 0) return intPortion; else return intPortion + '.' + decPortion; // old buggy code: // var power : int = Math.pow(10, decimals); // return Math.round(raw * ( power )) / power; }
    unfortunately Nate Cook's code has a bug too... my final version for truncateNumber() now looks like this: function truncateNumber(raw : Number, decimals :int =2) : String { // Nate Cook's brainchild var intPortion:String = ''; var decPortion:String = ''; var value :String = String(raw); if (value.indexOf('.') == -1) { intPortion = (Math.abs(Number(value))).toString(); decPortion = "0"; } else { intPortion = (Math.abs(Number(value.substring(0,value.indexOf('.'))))).toString(); decPortion = value.substr(value.indexOf('.') + 1); } // create decimal portion if (Number(decPortion) == 0) { decPortion = ''; while (decPortion.length < decimals) decPortion += '0'; } else { if (decPortion.length > decimals) { var dec:Number = Math.round(Math.pow(10, decimals) * Number('0.' + decPortion)); if(((String(dec)).length > decimals) && (dec != 0)) { decPortion = '0'; intPortion = ((Math.abs(Number(intPortion)) + 1) * (Number(intPortion) >= 0 ? 1 : -1)).toString(); } else { decPortion = String(dec); // bugfix here: while(decPortion.length < decimals) decPortion = '0' + decPortion; } } if (decPortion.length < decimals) { decPortion = new String(decPortion); while(decPortion.length < decimals) decPortion += '0'; } } // combine pieces if(decimals == 0) return intPortion; else return intPortion + '.' + decPortion; // old buggy code: // var power : int = Math.pow(10, decimals); // return Math.round(raw * ( power )) / power; }
  • Jul 10, 2009
    issue 4 (SUBS_RE is buggy) commented on by helmut.messerer   -   in order to fix the decimals for this I adapted Nate Cooks AS2 sprintf class a bit and changed truncateNumber() as follows: function truncateNumber(raw : Number, decimals :int =2) : String { var intPortion:String = ''; var decPortion:String = ''; var value :String = String(raw); if (value.indexOf('.') == -1) { intPortion = (Math.abs(Number(value))).toString(); decPortion = "0"; } else { intPortion = (Math.abs(Number(value.substring(0,value.indexOf('.'))))).toString(); decPortion = value.substr(value.indexOf('.') + 1); } // create decimal portion if (Number(decPortion) == 0) { decPortion = ''; while (decPortion.length < decimals) decPortion += '0'; } else { if (decPortion.length > decimals) { var dec:Number = Math.round(Math.pow(10, decimals) * Number('0.' + decPortion)); if(((String(dec)).length > decimals) && (dec != 0)) { decPortion = '0'; intPortion = ((Math.abs(Number(intPortion)) + 1) * (Number(intPortion) >= 0 ? 1 : - 1)).toString(); } else decPortion = String(dec); } if (decPortion.length < decimals) { decPortion = new String(decPortion); while(decPortion.length < decimals) decPortion += '0'; } } // combine pieces if(decimals == 0) return intPortion; else return intPortion + '.' + decPortion; // var power : int = Math.pow(10, decimals); // return Math.round(raw * ( power )) / power; } seems to work for me.
    in order to fix the decimals for this I adapted Nate Cooks AS2 sprintf class a bit and changed truncateNumber() as follows: function truncateNumber(raw : Number, decimals :int =2) : String { var intPortion:String = ''; var decPortion:String = ''; var value :String = String(raw); if (value.indexOf('.') == -1) { intPortion = (Math.abs(Number(value))).toString(); decPortion = "0"; } else { intPortion = (Math.abs(Number(value.substring(0,value.indexOf('.'))))).toString(); decPortion = value.substr(value.indexOf('.') + 1); } // create decimal portion if (Number(decPortion) == 0) { decPortion = ''; while (decPortion.length < decimals) decPortion += '0'; } else { if (decPortion.length > decimals) { var dec:Number = Math.round(Math.pow(10, decimals) * Number('0.' + decPortion)); if(((String(dec)).length > decimals) && (dec != 0)) { decPortion = '0'; intPortion = ((Math.abs(Number(intPortion)) + 1) * (Number(intPortion) >= 0 ? 1 : - 1)).toString(); } else decPortion = String(dec); } if (decPortion.length < decimals) { decPortion = new String(decPortion); while(decPortion.length < decimals) decPortion += '0'; } } // combine pieces if(decimals == 0) return intPortion; else return intPortion + '.' + decPortion; // var power : int = Math.pow(10, decimals); // return Math.round(raw * ( power )) / power; } seems to work for me.
  • Jul 10, 2009
    issue 4 (SUBS_RE is buggy) reported by helmut.messerer   -   What steps will reproduce the problem? 1. printf("%.2f", 0.0) What is the expected output? What do you see instead? 2. returns %.2f 3. instead of 0.00 What version of the product are you using? On what operating system? last Please provide any additional information below. SUBS_RE seems wrong. i changed it to this instead: var SUBS_RE : RegExp = /%(?!^%)(\((?P<var_name>[\w_\d]+)\))?(?P<padding>[0-9]{1,2})?(\.(? P<precision>[0-9]+))?(?P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])/ig; note how the precision part is moved AFTER the padding and BEFORE the formater (as it should) this doesn't enforce .00 though (in case of %.2f when supplied integer arguments)
    What steps will reproduce the problem? 1. printf("%.2f", 0.0) What is the expected output? What do you see instead? 2. returns %.2f 3. instead of 0.00 What version of the product are you using? On what operating system? last Please provide any additional information below. SUBS_RE seems wrong. i changed it to this instead: var SUBS_RE : RegExp = /%(?!^%)(\((?P<var_name>[\w_\d]+)\))?(?P<padding>[0-9]{1,2})?(\.(? P<precision>[0-9]+))?(?P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])/ig; note how the precision part is moved AFTER the padding and BEFORE the formater (as it should) this doesn't enforce .00 though (in case of %.2f when supplied integer arguments)
  • Jul 10, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) commented on by helmut.messerer   -   there is a BUG: SUBS_RE should be like this instead: var SUBS_RE : RegExp = /%(?!^%)(\((?P<var_name>[\w_\d]+)\))?(?P<padding>[0-9]{1,2})?(\.(?P<precision>[0- 9]+))?(?P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])/ig;
    there is a BUG: SUBS_RE should be like this instead: var SUBS_RE : RegExp = /%(?!^%)(\((?P<var_name>[\w_\d]+)\))?(?P<padding>[0-9]{1,2})?(\.(?P<precision>[0- 9]+))?(?P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])/ig;
  • Jun 16, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) commented on by msielski   -   Having this problem in rev 16. This formats with 2 decimal precision: trace(printf("%f", 1.111); outputs 1.11 but this: trace(printf("%.2f", 1.111); outputs %.2f Fortunately the output of %2 is what I need so I'm using that.
    Having this problem in rev 16. This formats with 2 decimal precision: trace(printf("%f", 1.111); outputs 1.11 but this: trace(printf("%.2f", 1.111); outputs %.2f Fortunately the output of %2 is what I need so I'm using that.
  • Feb 21, 2009
    asprintf-rev-16.zip (as prinft rev 16. Src, docs and tests. Svn is more up to dat...) file uploaded by debert   -  
    Labels: Featured
    Labels: Featured
  • Feb 21, 2009
    r16 (Removed examples dir, since unit tests are a better example ) committed by debert   -   Removed examples dir, since unit tests are a better example
    Removed examples dir, since unit tests are a better example
  • Feb 21, 2009
    r15 (Added suport for escaping % inside strings ) committed by debert   -   Added suport for escaping % inside strings
    Added suport for escaping % inside strings
  • Feb 21, 2009
    r14 (Incorporated NullTests by gabriel into the main suite ) committed by debert   -   Incorporated NullTests by gabriel into the main suite
    Incorporated NullTests by gabriel into the main suite
  • Feb 21, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) Status changed by debert   -   Fixed in rev 7. Thanks for the report. Arthur
    Status: Fixed
    Fixed in rev 7. Thanks for the report. Arthur
    Status: Fixed
  • Feb 21, 2009
    printf-rev13.zip (as3-printf-rev13 Use of svn recommended. Includes src, docs,...) file uploaded by debert   -  
    Labels: Featured
    Labels: Featured
  • Feb 21, 2009
    r13 ( Added test cases for dates ) committed by debert   -   Added test cases for dates
    Added test cases for dates
  • Feb 21, 2009
    r12 (Fixed output for octal formatting ) committed by debert   -   Fixed output for octal formatting
    Fixed output for octal formatting
  • Feb 21, 2009
    r11 (Fixed output for octal formatting ) committed by debert   -   Fixed output for octal formatting
    Fixed output for octal formatting
  • Feb 21, 2009
    r10 (Makes sure if we don't can't find a proper substitution we r...) committed by debert   -   Makes sure if we don't can't find a proper substitution we removed the prinf format from resulting string.
    Makes sure if we don't can't find a proper substitution we removed the prinf format from resulting string.
  • Feb 21, 2009
    r9 (Removed traces ) committed by debert   -   Removed traces
    Removed traces
  • Feb 21, 2009
    r8 (Improved test suite and fixed padding issues. Refactored pa...) committed by debert   -   Improved test suite and fixed padding issues. Refactored padding code wich now should work mostly as expected. Also added quite a few test cases for numerical and padding substitutions
    Improved test suite and fixed padding issues. Refactored padding code wich now should work mostly as expected. Also added quite a few test cases for numerical and padding substitutions
  • Feb 20, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) commented on by drukepple   -   Just an "edit" to say that while the characters in my var SUBS_RE line seem to have been preserved, a hard line break was introduced between a "?" and the "P<formatter>", so if you're copying and pasting, be sure to make sure no whitespace exists in the regex after you paste.
    Just an "edit" to say that while the characters in my var SUBS_RE line seem to have been preserved, a hard line break was introduced between a "?" and the "P<formatter>", so if you're copying and pasting, be sure to make sure no whitespace exists in the regex after you paste.
  • Feb 20, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) commented on by drukepple   -   Hi, I was experiencing the same issue. I got into the regex that parses the raw string and it looks to me like we just need to move the "precision" capture, and place a "?" after it to make it optional. That is: line 48, first line of code of the printf function, might work better like this: var SUBS_RE : RegExp = /%(\((?P<var_name>[\w_\d]+)\))?(?P<padding>0[0-9])?(\.(?P<precision>[0-9]+))?(? P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])?/ig; (hopefully that doesn't get destroyed by the HTML page) I did not test this against the various test files, just tested that %.2f and %s both seem to work with that change. Sorry...but I've got a deadline to meet!
    Hi, I was experiencing the same issue. I got into the regex that parses the raw string and it looks to me like we just need to move the "precision" capture, and place a "?" after it to make it optional. That is: line 48, first line of code of the printf function, might work better like this: var SUBS_RE : RegExp = /%(\((?P<var_name>[\w_\d]+)\))?(?P<padding>0[0-9])?(\.(?P<precision>[0-9]+))?(? P<formater>[sxofaAbBcdHIjmMpSUwWxXyYZ])?/ig; (hopefully that doesn't get destroyed by the HTML page) I did not test this against the various test files, just tested that %.2f and %s both seem to work with that change. Sorry...but I've got a deadline to meet!
  • Jan 05, 2009
    issue 3 (Formatting a numeric value with a fixed number of decimal pl...) reported by lorenzo.wood   -   What steps will reproduce the problem? 1. import the printf 2. execute the code v = printf("%.2f", v), with v an untyped variable originally containing a floating point number (eg, 0.4858329, 5.094833) 3. look at v What is the expected output? What do you see instead? v should contain a string with the numeric value to two DP (eg, "0.486", "5.095" for the example values). In fact, it simply repeats the formatting string (eg, "%.2f" for all values of v). Removing the ".2" qualification, leaving a format string of "%f", produces the expected result. What version of the product are you using? On what operating system? The ZIP file describes itself as "rev6". Running Adobe Flash CS3 and Flash Player 9 on Windows XP SP3. Please provide any additional information below.
    What steps will reproduce the problem? 1. import the printf 2. execute the code v = printf("%.2f", v), with v an untyped variable originally containing a floating point number (eg, 0.4858329, 5.094833) 3. look at v What is the expected output? What do you see instead? v should contain a string with the numeric value to two DP (eg, "0.486", "5.095" for the example values). In fact, it simply repeats the formatting string (eg, "%.2f" for all values of v). Removing the ".2" qualification, leaving a format string of "%f", produces the expected result. What version of the product are you using? On what operating system? The ZIP file describes itself as "rev6". Running Adobe Flash CS3 and Flash Player 9 on Windows XP SP3. Please provide any additional information below.

Older

  • Nov 04, 2008
    r7 (Removed debug-traces and errors: if something goes wrong (li...) committed by gabriel.laet   -   Removed debug-traces and errors: if something goes wrong (like null values), we just return an empty string or the raw string. Added NullTests to the test-suite.
    Removed debug-traces and errors: if something goes wrong (like null values), we just return an empty string or the raw string. Added NullTests to the test-suite.
  • Sep 14, 2008
    issue 2 (Leading Zeros) Status changed by debert   -   Fixed in revision 6. Thanks for the patch, David. Cheers Arthur Debert
    Status: Fixed
    Fixed in revision 6. Thanks for the patch, David. Cheers Arthur Debert
    Status: Fixed
  • Sep 14, 2008
    r6 (Added a basic test suite. Fixed wrong precison regex. Implem...) committed by debert   -   Added a basic test suite. Fixed wrong precison regex. Implemented zero padding, thanks David Rio Gomes ( issue 2 ).
    Added a basic test suite. Fixed wrong precison regex. Implemented zero padding, thanks David Rio Gomes ( issue 2 ).
  • Aug 11, 2008
    issue 2 (Leading Zeros) commented on by debert   -   Hi David. At a quick glance this looks good. As soon as I get some time I'll check this in. Thanks for the code Arthur
    Hi David. At a quick glance this looks good. As soon as I get some time I'll check this in. Thanks for the code Arthur
  • Aug 11, 2008
    issue 2 (Leading Zeros) commented on by david.rios.gomes   -   heres an implementation of this feature
    heres an implementation of this feature
  • Aug 01, 2008
    r5 (- fixed collon at version identifier, thanks Igor Almeida) committed by debert   -   - fixed collon at version identifier, thanks Igor Almeida
    - fixed collon at version identifier, thanks Igor Almeida
 
Hosted by Google Code