jastroem
asked on
format a string (larger number - filesize) as n kB
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
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jimmy282
right - that's exactly what I need!
thank you both
/joergen
right - that's exactly what I need!
thank you both
/joergen
<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.