Link | bytes_format |
Author | Jason Huck |
Category | File |
Version | 8.x |
License | http://opensource.org/licenses/artistic-license.php |
Posted | 25 Oct 2005 |
Updated | 16 Jan 2006 |
More by this author... |
Tags the supplied integer as a number of bytes and returns it as a string converted to kb, mb, or gb, depending on the size.
var('myFile') = file( 'somefile.txt', file_openread, file_modechar ); bytes_format($myFile->getsize); -> 2.23 mb
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( 'format', -namespace='bytes_', -priority='replace', -description='Converts bytes to kilobytes, megabytes, or gigabytes for display.' ); fail_if( !params->first || !params->first->isa('integer'), -1, '[bytes_format] requires an integer as input.' ); local( 'in' = decimal(params->first), 'd' = decimal(1024), 'c' = 1, 'u' = array( 'bytes', 'kb', 'mb', 'gb' ) ); #in->setformat( -precision=2); while(true); if(#in < #d); local('out') = (#c == 1 ? integer(#in) | #in); return(#out + ' ' + #u->get(#c)); else; #in /= #d; #c += 1; /if; /while; /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft