mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
Calculator兼容x
字符作为乘号(issue#3787@Github)
This commit is contained in:
parent
4a860c77ff
commit
62d31e4656
@ -2,11 +2,12 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.34(2024-11-13)
|
||||
# 5.8.34(2024-11-15)
|
||||
|
||||
### 🐣新特性
|
||||
* 【http 】 增加Windows微信浏览器识别(issue#IB3SJF@Gitee)
|
||||
* 【core 】 ZipUtil.unzip增加编码容错(issue#I3UZ28@Gitee)
|
||||
* 【core 】 Calculator兼容`x`字符作为乘号(issue#3787@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复DateUtil.rangeToList中step小于等于0时无限循环问题(issue#3783@Github)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.math;
|
||||
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
@ -192,6 +193,9 @@ public class Calculator {
|
||||
arr[i] = '~';
|
||||
}
|
||||
}
|
||||
} else if(CharUtil.equals(arr[i], 'x', true)){
|
||||
// issue#3787 x转换为*
|
||||
arr[i] = '*';
|
||||
}
|
||||
}
|
||||
if (arr[0] == '~' && (arr.length > 1 && arr[1] == '(')) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cn.hutool.core.math;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CalculatorTest {
|
||||
|
||||
@Test
|
||||
@ -55,4 +56,14 @@ public class CalculatorTest {
|
||||
final double calcValue = Calculator.conversion("(11+2)12");
|
||||
assertEquals(156D, calcValue, 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void issue3787Test() {
|
||||
final Calculator calculator1 = new Calculator();
|
||||
double result = calculator1.calculate("0+50/100x(1/0.5)");
|
||||
assertEquals(1D, result);
|
||||
|
||||
result = calculator1.calculate("0+50/100X(1/0.5)");
|
||||
assertEquals(1D, result);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user