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

前端 未结 16 1523
忘了有多久
忘了有多久 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:00

    Though Excel format conditions will only display 1 of 3 conditions related to number size (they code it as "positive; negative; zero; text" but I prefer to see it as : if isnumber and true; elseif isnumber and false; elseif number; elseif is text )

    so to me the best answer is David's as well as Grastveit's comment for other regional format.

    Here are the ones I use depending on reports I make.

    [<1000000]#,##0.00," KB";[<1000000000]#,##0.00,," MB";#,##0.00,,," GB"
    
    [>999999999999]#,##0.00,,,," TB";[>999999999]#,##0.00,,," GB";#.##0.00,," MB"
    
    [<1000000]# ##0,00 " KB";[<1000000000]# ##0,00  " MB";# ##0,00   " GB"
    
    [>999999999999]# ##0,00    " TB";[>999999999]# ##0,00   " GB";# ##0,00  " MB"
    

    Take your pick!

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

    I don't know of a way to make it show you binary gigabytes (multiples of 1024*1024*1024) but you can make it show you decimal gigabytes using a format like:

    0.00,,,"Gb"
    
    0 讨论(0)
  • 2020-12-22 19:03

    After seeing the answers here just improved on this formula to have decimal places on bigger values and cater for negative values.

    =IF(A1<999500000000,TEXT(A1,"#,##.#0,,,"" TB"""),
    IF(A1<-9995000000,TEXT(A1,"#,##.#0,,,"" GB"""),
    IF(A1<-9995000,TEXT(A1,"#,##0,,"" MB"""),
    IF(A1<-9995,TEXT(A1,"#,##0,"" KB"""),
    IF(A1<-1000,TEXT(A1,"#,##0"" B """),
    IF(A1<0,TEXT(A1,"#,##0"" B """),
    IF(A1<1000,TEXT(A1,"#,##0"" B """),
    IF(A1<999500,TEXT(A1,"#,##0,"" KB"""),
    IF(A1<999500000,TEXT(A1,"#,##0,,"" MB"""),
    IF(A1<999500000000,TEXT(A1,"#,##.#0,,,"" GB"""),
    TEXT(A1,"#,##.#0,,,,"" TB""")))))))))))
    
    0 讨论(0)
  • 2020-12-22 19:04

    And, yet another solution, is to use engineering notation. (That's like scientific notation except the exponent is always a multiple of 3.) Right-click on the cell(s) and select Format Cells. Under the Number tab, select Custom. Then in the Type: box, put the following:

    ##0.00E+00
    

    Then click OK. Instead of K, M, etc, you'll have +3, +6, etc. This will work for positive and negative numbers, as well as positive and negative exponents, -3 is m, -6 is u, etc.

    567.00E-06
      5.67E-03
     56.70E-03
    567.00E-03
      5.67E+00
     56.70E+00
    567.00E+00
      5.67E+03
     56.70E+03
    567.00E+03
      5.67E+06
    
    0 讨论(0)
  • 2020-12-22 19:06

    Here is one that I have been using: -

    [<1000000]0.00," KB";[<1000000000]0.00,," MB";0.00,,," GB"
    

    Seems to work fine.

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

    Paste this next to your values(bytes) and this will automatically change it to whatever your size of value is.

    =IF(G10>=1099511627776,CONCATENATE(ROUND((G10/1024/1024/1024/1024),1)," TB"),IF(G10>=1073741824,CONCATENATE(ROUND((G10/1024/1024/1024),1)," GB"),IF(G10>=1048576,CONCATENATE(ROUND((G10/1024/1024),1)," MB"),IF(G10>=1024,CONCATENATE(ROUND((G10/1024),1)," KB"),IF(G10>=1,CONCATENATE((G10)," BYTES"),0)))))

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