I'm using Handlebar template in my backbone application.
In some part of my application, I'm getting size of a file in bytes. And I want to show that in the front-end, but not in bytes but in Byes, KB, MB, GB depending on the size of the file.
I can easily do that using if else block and the byte value of KB, MB, GB. e.g
HandleBars.registerHelper('filesize', function(bytes) {
if(bytes < 1024)
return bytes+'Bytes'
else if(bytes >= 1024 && bytes < 1048576)
return (bytes/1024) + 'KB'
});
Can anybody suggest me, the better method to do this.