fix date size bug

This commit is contained in:
Looly 2020-09-08 15:42:29 +08:00
parent 4d7b795505
commit fd51eb08b4
3 changed files with 9 additions and 2 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.4.2 (2020-09-07)
# 5.4.2 (2020-09-08)
### 新特性
* 【core 】 lock放在try外边pr#1050@Github
@ -24,6 +24,7 @@
* 【poi 】 修复CglibUtil.copyList参数错误导致的问题
* 【http 】 修复GET请求附带body导致变POST的问题
* 【core 】 修复double相等判断问题pr#175@Gitee
* 【core 】 修复DateSizeUtil.format越界问题issue#1069@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -31,7 +31,7 @@ public class DataSizeUtil {
if (size <= 0) {
return "0";
}
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
int digitGroups = Math.min(DataUnit.UNIT_NAMES.length-1, (int) (Math.log10(size) / Math.log10(1024)));
return new DecimalFormat("#,##0.##")
.format(size / Math.pow(1024, digitGroups)) + " " + DataUnit.UNIT_NAMES[digitGroups];
}

View File

@ -19,4 +19,10 @@ public class DataSizeUtilTest {
parse = DataSizeUtil.parse("3mb");
Assert.assertEquals(3145728, parse);
}
@Test
public void formatTest(){
final String format = DataSizeUtil.format(Long.MAX_VALUE);
Assert.assertEquals("8,192 EB", format);
}
}