Lasso Soft Inc. > Home


AuthorBil Corry
LicensePublic Domain
Posted02 Sep 2006
Updated02 Sep 2006
More by this author...


Returns the filesize formatted for display given the number of bytes.

Requires [lp_decimal_float] [lp_decimal_fixed]

Sample Usage

lp_display_filesize: 2023940;'
'; lp_display_filesize: 2023940, -kb;'
'; Returns: 1.93 MB 1,977 KB

Source Code

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.


	-description='Returns the filesize formatted for display given the number of bytes.',
	-optional='kb', 	// returns everything in kilobytes
	// based on a tag from Jason Huck

	// and Pier Kuipers
		'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);
			local:'return' = ((lp_decimal_fixed: #bytes / #blocksize) + 1);
		#return->(setformat: -groupchar=',');
		return: #return ' KB';
	#bytes->(setformat: -precision=2);
	while: true;
		if: #bytes < #blocksize;
			return: (#exp <= 2 ? (integer:#bytes) | #bytes) ' ' #units->(get:#exp);
		else; // >=
			#bytes /= #blocksize;
			#exp += 1;



Related Tags


No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft