Skip to content
Advertisement

Javascript Human Readable Filesize

I am currently trying to convert this php function to javascript:

JavaScript

Here’s what I have so Far:

JavaScript

Im Just struggling with the last line. Any Help Greatly Appreciated.

Advertisement

Answer

Did you have a look at: http://programanddesign.com/js/human-readable-file-size-in-javascript/ They have two version of a Javascript solution for Human Readable Filesize:

JavaScript

and

JavaScript

Update loop criteria to while(size >= 1024 && i < units.length - 1) to prevent undefined after YB or last unit exceeded as mentioned by @holytrousers.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement