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

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

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

Hope someone can help me!

/ joergen
Question by:jastroem
  • 2

Expert Comment

Comment Utility
Something like this should work:

<cfset kb = int(round(34789/1000))>
34789 = <cfoutput>#kb#</cfoutput> kB
<cfset kb = int(round(34236/1000))>
34236 = <cfoutput>#kb#</cfoutput> kB
<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.

Author Comment

Comment Utility

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
LVL 11

Accepted Solution

jimmy282 earned 70 total points
Comment Utility
Here it is!

<CFIF SIZE lt 2000>                                                                                          #Trim(NumberFormat(SIZE,'____'))#&nbsp;bytes
               <CFELSEIF SIZE gt 2000000>

Size is the variable u want to change.


Author Comment

Comment Utility

right - that's exactly what I need!

thank you both


Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Domain Name E-mail Address & Outlook Integration 3 35
Help Fix A 403 error 13 94
Problem to Eclipse 16 99
Problem to go to Web page 2 48
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…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

17 Experts available now in Live!

Get 1:1 Help Now