Solved

format a string (larger number - filesize) as n kB

Posted on 2002-05-11
4
214 Views
Last Modified: 2013-12-24
How can I format a string that holds a number like:

34789 to be displayed as 35 kB
or
34236 to be displayed as 34 kB
or
123612 to be displayed as 124 kB

Hope someone can help me!

/ joergen
0
Comment
Question by:jastroem
  • 2
4 Comments
 
LVL 1

Expert Comment

by:ndintenfass
ID: 7003468
Something like this should work:

<cfset kb = int(round(34789/1000))>
34789 = <cfoutput>#kb#</cfoutput> kB
<br>
<cfset kb = int(round(34236/1000))>
34236 = <cfoutput>#kb#</cfoutput> kB
<br>
<cfset kb = int(round(123612/1000))>
123612 = <cfoutput>#kb#</cfoutput> kB

Also, don't forget that

1024 bytes = 1 KB

so, the math is not necessarily this simple, but those are the numbers you asked for.
0
 

Author Comment

by:jastroem
ID: 7004344
ndintenfass

Thank you for your answer!


>Also, don't forget that
>1024 bytes = 1 KB

So then it should be?

<cfset kb = int(round(34789/1024))>
34789 = <cfoutput>#kb#</cfoutput> kB

/ joergen
0
 
LVL 11

Accepted Solution

by:
jimmy282 earned 70 total points
ID: 7005358
Here it is!

<CFIF SIZE lt 2000>                                                                                          #Trim(NumberFormat(SIZE,'____'))#&nbsp;bytes
               <CFELSEIF SIZE gt 2000000>
#Trim(NumberFormat(SIZE/1024/1024,'__________.0'))#&nbsp;M
               <CFELSE>
#Trim(NumberFormat(SIZE/1024,'____'))#&nbsp;K
               </CFIF>

Size is the variable u want to change.

Jimmy
0
 

Author Comment

by:jastroem
ID: 7005447
jimmy282

right - that's exactly what I need!

thank you both

/joergen
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now