[PK_ByteSize]

Description

Link: [PK_ByteSize]
Author: Pier Kuipers
Category: Bytes
Version: 7.x
License: Public Domain
Posted: Nov. 16, 2005
Updated: Nov. 16, 2005
More by this author...
OK, Jason has already added a tag that does this, but I just happened to have this one floating around. The tag will take an integer which is assumed to be a number of bytes, and makes it readable, appending the appropriate "K", "MB", "GB" or "TB" at the end.

Parameters

none


Sample Usage

[PK_ByteSize:4427780] -> 4.20 MB
						

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
<?LassoScript

	if: !(lasso_tagexists:'PK_ByteSize');

		Define_Tag: 'PK_ByteSize', -Required = 'size';
		
			Local: 'size' = @(Params->(Get:1));
			Local: 'displaysize' = (string);
			
				local:'kb' = 1024;  
				local:'mb' = 1024 * #kb;
				local:'gb' = 1024 * #mb;
				local:'tb' = 1024 * #gb;

				if:(#size < #kb); 
					local:'displaysize' = (#size + ' Bytes');
				Else: (#size < #mb); 
					local:'displaysize' = ((decimal: #size) / #kb);
					#displaysize -> setformat: -precision=0;
					#displaysize += ' KB';
				Else: (#size < #gb); 
					local:'displaysize' = ((decimal: #size) / #mb);
					#displaysize -> setformat: -precision=2;
					#displaysize += ' MB';
				Else: (#size < #tb); 
					local:'displaysize' = ((decimal:#size) / #gb);
					#displaysize -> setformat: -precision=2;
					#displaysize += ' GB';
				Else;
					var:'displaysize' = ((decimal:#size) / #tb);
					#displaysize->setformat: -precision=2;
					#displaysize += ' TB';
				/If;
			
			return: #displaysize ;

		/Define_Tag;

	/if;

?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular