Converting KB to MB, GB, TB dynamically

后端 未结 10 1969
广开言路
广开言路 2020-12-14 18:24
public String size(int size){
    String hrSize = \"\";
    int k = size;
    double m = size/1024;
    double g = size/1048576;
    double t = size/1073741824;

            


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 19:17

    You are performing integer division,

    i.e., 31/15 will result in 2, not 2.whatever

    just append the number with D or d which denotes it as a double and you will be fine

    double m = size/1024D;
    double g = size/1048576D;
    double t = size/1073741824D;
    

提交回复
热议问题