[lp_display_filesize]

Description

Link: [lp_display_filesize]
Author: Bil Corry
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Sep. 02, 2006
Updated: Sep. 02, 2006
More by this author...
Returns the filesize formatted for display given the number of bytes.

Requires [lp_decimal_float] [lp_decimal_fixed]

Parameters

-filesize integer, required The file size in bytes.
-kb boolean, optional Always return the file size in kilobytes.

Sample Usage

lp_display_filesize: 2023940;'<br>';
lp_display_filesize: 2023940, -kb;'<br>';

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[

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;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular