rejetto forum

Bytes to kilobytes?

0 Members and 1 Guest are viewing this topic.

Offline RandomClown

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
I have no idea how to type this into the search.
I am redesigning the entire template from a blank text file.
All I have left is the bandwidth monitor.

At this part:

down  File Name.ext
7415952 / 222146469 bytes
Speed: 980.0 KB/s

Is there a way to change the size to kilobytes?
or do I have to use JavaScript?

Its a little too much for my eyes, & I might cut it out if I cant make it shorter.
Otherwise the program is awesome! Nice work on it!

Anyone want to give it a test run?
HoRC.mine.nu
Last link. If any viewers finds a bug, can you report it?
thanks!


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
yeah, have a look in the wiki for the section about template macros. The link for it is in the template section.

Use the div macro to divide the amount of bytes by 1000 to get the amount in kilobytes.

By using the macro system in the template everything is evaluated at the server and there wont be any compatibility issues for javascript being enabled, etc.


Offline RandomClown

  • Occasional poster
  • *
    • Posts: 4
    • View Profile

Offline RandomClown

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
Ohhh no wonder it wasnt working.

=====
Macros are not available in current version 2.2, but they will in 2.3, and you can experiment with it using beta versions.
=====

Time to find the beta! :D


Offline RandomClown

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
I tried out the beta version.
It works ok. A lot of writing & thinking though.
Is the macro still under developement?

I now use the macro to hide files from non-logged in users.
Before I moved the HTML under %loggedin% & the HTML would not appear right in the upload page, so            I cut it out. Now I can bring it back!

I could not figure out too well on how to make the size change depending on the current display size.

I tried Javascript instead & it works great!

Anyone interested in the code, this is my version:
Simply paste the code in the bandwidth monitor. Tweak the code for more effects.
===========================
<script language="javascript">
var Bytes=%done-bytes%;
if(Bytes>=1024&&Bytes<1048576){document.write(Math.round(Bytes/1024)+"KB")}
if(Bytes>=1048576&&Bytes<1073741824){document.write(Math.round(Bytes/1024/1024)+"MB")}
if(Bytes>=1073741824){document.write(Math.round(Bytes/1024/1024)+"GB")}
</script>
/
<script language="javascript">
var Bytes=%total-bytes%;
if(Bytes>=1024&&Bytes<1048576){document.write(Math.round(Bytes/1024)+"KB")}
if(Bytes>=1048576&&Bytes<1073741824){document.write(Math.round(Bytes/1024/1024)+"MB")}
if(Bytes>=1073741824){document.write(Math.round(Bytes/1024/1024)+"GB")}
</script>
===========================

- It will change to KB if the file size exceeds 1024Bytes.
- It will change to MB if the file size exceeds 1024KiloBytes.
- It will change to GB if the file size exceeds 1024MegaBytes.

Average computer does not have over a TeraByte, nor would anyone want to send data for soo long, so no point in adding it to the code. [unless you just want to have it :D]
« Last Edit: July 06, 2008, 06:34:14 AM by RandomClown »


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
I could not figure out too well on how to make the size change depending on the current display size.

I achieved that for my apche style template by creating a macro for each size B, KB, MB, etc.

Code: ('Apache style template') [Select]
{{set| size-B |{{\{{if|{{>=|$1|1024}}|{{^size-K|{{div|$1|1024}}}}|{{^sizeb|$1|4}}}}/}}}}
{{set| size-K |{{\{{if|{{>=|$1|1024}}|{{^size-M|{{div|$1|1024}}}}|{{^size|$1K|4}}}}/}}}}
{{set|size-M|{{\{{if|{{>=|$1|1024}}|{{^size-G|{{div|$1|1024}}.{{cut|1|1|{{mod|$1|1024}}}}}}|{{^size|$1M|4}}}}/}}}}
{{set|size-G|{{\{{if|{{>=|$1|1024}}|ERROR|{{^size|$1G|4}}}}/}}}}

aslong as you set the template to output the file sizes as bytes and send it as the parameter of size-B it should work.

But why do you need a macro to do that? the symbol %item-size% does that automatically for you.