Link | lp_display_filesize |
Author | Bil Corry |
Category | Utility |
Version | 8.5.x |
License | Public Domain |
Posted | 02 Sep 2006 |
Updated | 02 Sep 2006 |
More by this author... |
Returns the filesize formatted for display given the number of bytes.
Requires [lp_decimal_float] [lp_decimal_fixed]
lp_display_filesize: 2023940;'
'; lp_display_filesize: 2023940, -kb;'
'; Returns: 1.93 MB 1,977 KB
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
[ define_tag:'lp_display_filesize', -description='Returns the filesize formatted for display given the number of bytes.', -priority='replace', -required='filesize', -optional='kb', // returns everything in kilobytes -encodenone; // based on a tag from Jason Huck // http://tagswap.net/bytes_format // and Pier Kuipers // http://tagswap.net/PK_ByteSize local: 'bytes' = decimal: #filesize, 'blocksize' = 1024.0, 'exp' = 1, 'units' = (:'B ','KB','MB','GB','TB'); if: (local_defined:'kb'); if: (lp_decimal_float: #bytes / #blocksize) == 0; local:'return' = (lp_decimal_fixed: #bytes / #blocksize); else; local:'return' = ((lp_decimal_fixed: #bytes / #blocksize) + 1); /if; #return->(setformat: -groupchar=','); return: #return ' KB'; /if; #bytes->(setformat: -precision=2); while: true; if: #bytes < #blocksize; return: (#exp <= 2 ? (integer:#bytes) | #bytes) ' ' #units->(get:#exp); else; // >= #bytes /= #blocksize; #exp += 1; /if; /while; /define_tag; ]
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft