Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2002-05-11
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 7003468
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

ID: 7004344

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 280 total points
ID: 7005358
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

ID: 7005447

right - that's exactly what I need!

thank you both


Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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