Converting bytes to GB in C#?

前端 未结 13 928
孤城傲影
孤城傲影 2020-12-23 12:09

I was refactoring some old code and came across the following line of code to convert bytes to GB.

decimal GB = KB / 1024 / 1024 / 1024;

Is

13条回答
  •  粉色の甜心
    2020-12-23 12:11

    In theory, this is faster (precomputing the constant to do multiplication instead of division). It's probably not used often enough to matter, but just in case.

    double const KbToGbFactor = 1d / 1024 /1024;
    
    double gb = kb * KbToGbFactor;
    

提交回复
热议问题