Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-05-11
4
Medium Priority
?
219 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 280 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

971 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