Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just Checking correctness (byte->kb->mb)

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
on my Webbased email I've been writing, I have a routine that takes the size(which is in bytes) , and converts it to a more friendly format (showing, b, kb, mb)

I'm just wondering if I am using the right key numbers and deviders

Code:
	<%
	Size = Cint(msg.Size)
	if size < 1024 then
		Sizer = Size & &quot;b&quot;
	elseif size > 1024 and size < 1024000 then
		Sizer = FormatNumber((Size/1024),2) & &quot;Kb&quot;
	elseif size > 1048576 then
		Sizer = FormatNumber(((Size/1024)/1024), 2) & &quot;Mb&quot;
	end if
	%>

I have it based around binary , 256->512->1024->2048, so forth, so I assume that 1024 megs = 1 Gig, 1024 kb = 1 Meg, 1024 Bytes = 1 Kb Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
ack, first elseif, the less than ... should be the same number, as seen on the second elseif , as the way I intended it. Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Hi Karl,

Your correct. I've just got three comments I'd like to add.

First, you really dont need all those conditions. Example:
if size < 1024 then
Sizer = Size & &quot;B&quot;
elseif size < 1048576 then
Sizer = FormatNumber((Size/1024),2) & &quot;KB&quot;
else
Sizer = FormatNumber(((Size/1048576), 2) & &quot;MB&quot;
end if

Second, lowercase b is used to indicate bits, not bytes. Uppercase is used to indicate bytes, as per the previous example. I know, it's knit picky, but politically correct.

Third, you might want to use a Long ISO an Integer. IIRC, the max value for a 2 byte Integer is around 32K while a 4 byte Long is just over 2 billion. Jon Hawkins
 
well I cant exactly use types, when developing in ASP , everything is a varient, so I have no control over that, but I'm sure you meant the CInt that I was using to pull the value out of msg.size Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
oh also , I removed the CInt( ) around the msg.size, seems to do good without, that way I can pull the exact value the Jmail componet holds it at (no constraint) Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top