[bytes_format]

Description

Link: [bytes_format]
Author: Jason Huck
Category: File
Version: 8.x
License:
Posted: Oct. 25, 2005
Updated: Jan. 16, 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.

Parameters

none


Sample Usage

var('myFile') = file(
    'somefile.txt', 
    file_openread,
    file_modechar
);

bytes_format($myFile->getsize);

-> 2.23 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
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;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net