mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix date size bug
This commit is contained in:
parent
4d7b795505
commit
fd51eb08b4
@ -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)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user