Calculate interest rate percentage

I am creating a progress bar on file upload. I currently have a upload form that returns the current amount of downloaded data. So, it starts from zero and returns the current size in bits, but I converted it to bytes.

If I can get the total file size before I upload it, and you can load the current amount and return it dynamically, how can I calculate this so that I can use a value of 1-100% for css width?

I am using the jQuery swfupload plugin: http://blogs.bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin

+4
source share
2 answers

Loaded percent = 100 / file size * Loaded bytes

Remember to use the same units for both sizes.

Hello

+1
source

Say the maximum width of your CSS for the progress bar (DIV?) Is 770px. Name this PROGRESS_MAX.

If the file size in bytes is FILE_SIZE and the number of bytes downloaded is UPLOADED_BYTES, then the current progress value (width in pixels) is UPLOADED_BYTES / FILE_SIZE * PROGRESS_MAX

Hope you are looking.

+3
source

All Articles