mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
rebase
This commit is contained in:
commit
dd716482e2
@ -25,6 +25,7 @@
|
||||
* 【system 】 修复CpuInfo.getUsed()方法(issue#2116@Github)
|
||||
* 【dfa 】 修复密集匹配和贪婪匹配冲突问题(issue#2126@Github)
|
||||
* 【db 】 修复c3p0丢失信息问题(issue#I4T7XZ@Gitee)
|
||||
* 【http 】 修复Action中HttpExchange没有关闭问题
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.7.20 (2022-01-20)
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
@ -153,6 +154,27 @@ public class NumberChineseFormatter {
|
||||
return chineseStr.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 阿拉伯数字(支持正负整数)四舍五入后转换成中文节权位简洁计数单位,例如 -5_5555 =》 -5.56万
|
||||
*
|
||||
* @param amount 数字
|
||||
* @return 中文
|
||||
*/
|
||||
public static String formatSimple(long amount) {
|
||||
if (amount < 1_0000 && amount > -1_0000) {
|
||||
return String.valueOf(amount);
|
||||
}
|
||||
String res;
|
||||
if (amount < 1_0000_0000 && amount > -1_0000_0000) {
|
||||
res = NumberUtil.div(amount, 1_0000, 2) + "万";
|
||||
} else if (amount < 1_0000_0000_0000L && amount > -1_0000_0000_0000L) {
|
||||
res = NumberUtil.div(amount, 1_0000_0000, 2) + "亿";
|
||||
} else {
|
||||
res = NumberUtil.div(amount, 1_0000_0000_0000L, 2) + "万亿";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化-999~999之间的数字<br>
|
||||
* 这个方法显示10~19以下的数字时使用"十一"而非"一十一"。
|
||||
|
@ -175,6 +175,26 @@ public class NumberChineseFormatterTest {
|
||||
Assert.assertEquals("零点零伍", f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatSimpleTest() {
|
||||
String f1 = NumberChineseFormatter.formatSimple(1_2345);
|
||||
Assert.assertEquals("1.23万", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(-5_5555);
|
||||
Assert.assertEquals("-5.56万", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(1_2345_6789);
|
||||
Assert.assertEquals("1.23亿", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(-5_5555_5555);
|
||||
Assert.assertEquals("-5.56亿", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(1_2345_6789_1011L);
|
||||
Assert.assertEquals("1.23万亿", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(-5_5555_5555_5555L);
|
||||
Assert.assertEquals("-5.56万亿", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(123);
|
||||
Assert.assertEquals("123", f1);
|
||||
f1 = NumberChineseFormatter.formatSimple(-123);
|
||||
Assert.assertEquals("-123", f1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void digitToChineseTest() {
|
||||
String digitToChinese = Convert.digitToChinese(12_4124_1241_2421.12);
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
import com.sun.net.httpserver.HttpContext;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
@ -12,7 +13,7 @@ import java.nio.charset.Charset;
|
||||
* @author looly
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public class HttpServerBase {
|
||||
public class HttpServerBase implements Closeable {
|
||||
|
||||
final static Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
|
||||
|
||||
@ -45,4 +46,12 @@ public class HttpServerBase {
|
||||
public HttpContext getHttpContext() {
|
||||
return getHttpExchange().getHttpContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用{@link HttpExchange#close()},关闭请求流和响应流
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
this.httpExchange.close();
|
||||
}
|
||||
}
|
||||
|
@ -33,5 +33,6 @@ public class ActionHandler implements HttpHandler {
|
||||
new HttpServerRequest(httpExchange),
|
||||
new HttpServerResponse(httpExchange)
|
||||
);
|
||||
httpExchange.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user