Solved

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

Posted on 2002-05-11
4
213 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

23 Experts available now in Live!

Get 1:1 Help Now