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

前端 未结 16 1521
忘了有多久
忘了有多久 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 18:53

    I use CDH hadoop and when I export excel report, I have two problems;

    1) convert Linux date to excel date,
    For that, add an empty column next to date column lets say the top row is B4, paste below formula and drag the BLACK "+" all the way to your last day at the end of the column. Then hide the original column

    =(((B4/1000/60)/60)/24)+DATE(1970|1|1)+(-5/24)
    

    2) Convert disk size from byte to TB, GB, and MB
    the best formula for that is this

    [>999999999999]# ##0.000,,,," TB";[>999999999]# ##0.000,,," GB";# ##0.000,," MB"
    

    it will give you values with 3 decimals just format cells --> Custom and paste the above code there

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

    You can't really do calculations in the formatting features of Excel. You can use something like the following to do a rough estimation though:

    [<500000]#,##0" B";[<500000000]#,##0,," MB";#,##0,,," GB"
    
    0 讨论(0)
  • 2020-12-22 18:55

    The above formatting approach works but only for three levels. The above used KB, MB, and GB. Here I've expanded it to six. Right-click on the cell(s) and select Format Cells. Under the Number tab, select Custom. Then in the Type: box, put the following:

    [<1000]##0.00"  B";[<1000000]##0.00," KB";##0.00,," MB"
    

    Then select OK. This covers B, KB, and MB. Then, with the same cells selected, click Home ribbon, Conditional Formatting, New Rule. Select Format only cells that contain. Then below in the rule description, Format only cells with, Cell Value, greater than or equal to, 1000000000 (that's 9 zeros.) Then click on Format, Number tab, Custom, and in the Type: box, put the following:

    [<1000000000000]##0.00,,," GB";[<1000000000000000]##0.00,,,," TB";#,##0.00,,,,," PB"
    

    Select OK, and OK. This conditional formatting will take over only if the value is bigger than 1,000,000,000. And it will take care of the GB, TB, and PB ranges.

    567.00  B
      5.67 KB
     56.70 KB
    567.00 KB
      5.67 MB
     56.70 MB
    567.00 MB
      5.67 GB
     56.70 GB
    567.00 GB
      5.67 TB
     56.70 TB
    567.00 TB
      5.67 PB
     56.70 PB
    

    Anything bigger than PB will just show up as a bigger PB, e.g. 56,700 PB. You could add another conditional formatting to handle even bigger values, EB, and so on.

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

    Less than Tera will write on GB & more than 999 GB write on TB

    [<1000]0" GB";[>999]0.0," TB"

    OR

    [<1000]0" GB";[>=1000]0.0," TB"

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

    Above formula requires a minus sign in the first line: "=IF(A1<-999500000000"

    =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 18:59

    It is a bit of a "brute force" but works ;)

    =IF(E4/1000<1;CONCATENATE(E4;" bps");IF(E4/1000<1000;CONCATENATE(ROUND(E4/1000;2);" kbps");IF(E4/1000000<1000;CONCATENATE(ROUND(E4/1000000;2);" mbps");IF(E4/1000000000<1000;CONCATENATE(ROUND(E4/1000000000;2);" gbps")))))
    

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