on-internet
← Community

Javascript Human Readable Filesize

Stack Overflow ·

I am currently trying to convert this php function to javascript: function human_filesize($bytes, $decimals = 2) { $sz = 'BKMGTP'; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]; } Here's what I have so Far: function human_filesiz(bytes){ var decimals = 2; var sz = 'BKMGTP'; var factor = Math.floor((bytes.length - 1) / 3); return (bytes / Math.pow(1024, factor)); //return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]; } Im Just struggling with the last line. Any Help Greatly Appreciated.

Comments

Sign in or sign up to comment and upvote.

No comments yet.