Round number to only first decimal place

前端 未结 3 576
渐次进展
渐次进展 2021-01-21 10:17

I would like to know the available phone memory, so I wrote this code.

File path2 = Environment.getDataDirectory();
StatFs stat2 = new StatFs(path.getPath());
lo         


        
3条回答
  •  星月不相逢
    2021-01-21 11:03

    Have you tried using free = Math.round(free * 10) / 10d; instead of free = Math.round(size * 10) / 10d;? I don't see size as a defined variable.

    A simple test of

    double free = 5.654707363;
    free = Math.round(free * 10) / 10d;
    System.out.println(free);
    

    outputs 5.7.

提交回复
热议问题