How to return KB, MB and GB from Bytes using a public function

前端 未结 6 1546
囚心锁ツ
囚心锁ツ 2021-02-10 01:49

I\'m writing a "function" that returns a file\'s size (in B, KB, MB, GB).

The VB.Net code always gets the size in bytes first, so when a file\'s size (in Bytes)

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-10 01:52

    You need to divide by 1024 not 1000. 1 KB is not 1000 Bytes, it's 1024 bytes. 1 MB is not 1000 KB, it's 1024 KB, and so on.

    Here's a good site to explain all this: http://pc.net/helpcenter/answers/why_1024_bytes

提交回复
热议问题