2

I have a random question about conversion on this plugin. I apologise if it sounds stupid but I could not find anyone raise an issue with this or even talk about it. But this has me stumped. I am using this plugin https://github.com/blueimp/jQuery-File-Upload

I thought it was a bug but found this piece of code

    _formatFileSize: function (bytes) {
        if (typeof bytes !== 'number') {
            return '';
        }
        if (bytes >= 1000000000) {
            return (bytes / 1000000000).toFixed(2) + ' GB';
        }
        if (bytes >= 1000000) {
            return (bytes / 1000000).toFixed(2) + ' MB';
        }
        return (bytes / 1000).toFixed(2) + ' KB';
    },

According to this, KB are caculated using 1000bytes not 1024. So I am abit confused because windows is showing me 1024 when checking the file size, alot of stackoverflow questions show using 1024.

This shows answers with 1024 bytes PHP filesize MB/KB conversion

At the same time, there are answers here of doing it both ways. So my question is which one should I be using and should it matter?

Community
  • 1
  • 1
adam gouldie
  • 251
  • 3
  • 16

1 Answers1

2

There is a difference between MB and MiB.

Megabyte:

1,000 KB = 1 MB (decimal) (10^6 Byte = 1,000,000 Bytes)

Mebibyte:

1,024 KB = 1 MiB (binary) (2^20 Byte = 1,048,576 Bytes)
dave
  • 62,300
  • 5
  • 72
  • 93