How can I format bytes a cell in Excel as KB, MB, GB etc?

前端 未结 16 1522
忘了有多久
忘了有多久 2020-12-22 18:46

I have a value in a cell that\'s in bytes. But nobody can read 728398112238. I\'d rather it say 678.37GB

To write a formula to format it relatively easy (here\'s one

相关标签:
16条回答
  • 2020-12-22 19:15

    I suspect a lot of the answers here are outdated, as I did not get the expected result from the given answer.

    If you have value in KB that you would like to format according to the size, you can try the following.


    Formula

    [<1000]#" KB ";[<1000000]#0,00 " MB";0,## " GB"


    Initial Value (in KB) => Output

    952 => 952 KB

    1514 => 1.51 MB

    5122323 => 5.12 GB

    0 讨论(0)
  • 2020-12-22 19:16

    All the answers here supply values with powers of 10. Here is a format using proper SI units (multiples of 1024, i.e. Mebibytes, Gibibytes, and Tebibytes):

    [>1099511627776]#.##,,,," TiB";[>1073741824]#.##,,," GiB";0.##,," MiB"
    

    This supports MiB, GiB, and TiB showing two decimal places.

    0 讨论(0)
  • 2020-12-22 19:17

    Slight change to make it work on my region, Europe (. as thousands separator, comma as decimal separator):

    [<1000000]#.##0,00" KB";[<1000000000]#.##0,00.." MB";#.##0,00..." GB"
    

    Still same issue on data conversion (1000 != 1024) but it does the job for me.

    0 讨论(0)
  • 2020-12-22 19:18

    For the exact result, I'd rather calculate it, but using display format.

    Assuming A1 cell has value 29773945664927.

    1. Count the number of commas in B1 cell.

      =QUOTIENT(LEN(A1)-1,3)

    2. Divide the value by 1024^B1 in C1 cell.

      =A1/1024^B1

    3. Display unit in D1 cell.

      =SWITCH(B1, 5," PB", 4," TB", 3," GB", 2," MB",1," KB",0," B")

    4. Hide B1 cell.

    screenshot

    0 讨论(0)
提交回复
热议问题