This commit is contained in:
Looly 2023-02-03 17:58:55 +08:00
parent 0bb5dc3443
commit f8d7fe1daf

View File

@ -7,6 +7,8 @@ import org.junit.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.text.ParseException;
/**
* {@link NumberUtil} 单元测试类
@ -349,6 +351,14 @@ public class NumberUtilTest {
Assert.assertEquals("1234.56", bigDecimal.toString());
}
@Test
public void issue2878Test() throws ParseException {
// https://github.com/dromara/hutool/issues/2878
// 当数字中包含一些非数字字符时按照JDK的规则不做修改
final BigDecimal bigDecimal = NumberUtil.toBigDecimal("345.sdf");
Assert.assertEquals(NumberFormat.getInstance().parse("345.sdf"), bigDecimal.longValue());
}
@Test
public void parseIntTest() {
int number = NumberUtil.parseInt("0xFF");