Converting file size in bytes to human-readable string

后端 未结 19 2157
眼角桃花
眼角桃花 2020-11-28 17:58

I\'m using this function to convert a file size in bytes to a human-readable file size:

function getReadableFileSizeString(fileSizeInBytes) {
    var i = -1;         


        
19条回答
  •  一个人的身影
    2020-11-28 18:18

    It depends on whether you want to use the binary or decimal convention.

    RAM, for instance, is always measured in binary, so to express 1551859712 as ~1.4GiB would be correct.

    On the other hand, hard disk manufacturers like to use decimal, so they would call it ~1.6GB.

    And just to be confusing, floppy disks use a mixture of the two systems - their 1MB is actually 1024000 bytes.

提交回复
热议问题