| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.math.BigInteger;
|
| | | import java.math.RoundingMode;
|
| | | import java.nio.ByteBuffer;
|
| | | import java.nio.charset.Charset;
|
| | | import java.text.NumberFormat;
|
| | |
| | | */
|
| | | public static String[] toStrArray(String str)
|
| | | {
|
| | | if (StringUtils.isEmpty(str))
|
| | | {
|
| | | return new String[] {};
|
| | | }
|
| | | return toStrArray(",", str);
|
| | | }
|
| | |
|
| | |
| | |
|
| | | /**
|
| | | * 转换为boolean<br>
|
| | | * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
|
| | | * String支持的值为:true、false、yes、ok、no、1、0、是、否, 如果给定的值为空,或者转换失败,返回默认值<br>
|
| | | * 转换失败不会报错
|
| | | *
|
| | | * @param value 被转换的值
|
| | |
| | | case "yes":
|
| | | case "ok":
|
| | | case "1":
|
| | | case "是":
|
| | | return true;
|
| | | case "false":
|
| | | case "no":
|
| | | case "0":
|
| | | case "否":
|
| | | return false;
|
| | | default:
|
| | | return defaultValue;
|
| | |
| | | }
|
| | | if (value instanceof Double)
|
| | | {
|
| | | return new BigDecimal((Double) value);
|
| | | return BigDecimal.valueOf((Double) value);
|
| | | }
|
| | | if (value instanceof Integer)
|
| | | {
|
| | |
| | | */
|
| | | public static String toSBC(String input, Set<Character> notConvertSet)
|
| | | {
|
| | | char c[] = input.toCharArray();
|
| | | char[] c = input.toCharArray();
|
| | | for (int i = 0; i < c.length; i++)
|
| | | {
|
| | | if (null != notConvertSet && notConvertSet.contains(c[i]))
|
| | |
| | | */
|
| | | public static String toDBC(String text, Set<Character> notConvertSet)
|
| | | {
|
| | | char c[] = text.toCharArray();
|
| | | char[] c = text.toCharArray();
|
| | | for (int i = 0; i < c.length; i++)
|
| | | {
|
| | | if (null != notConvertSet && notConvertSet.contains(c[i]))
|
| | |
| | | String s = "";
|
| | | for (int i = 0; i < fraction.length; i++)
|
| | | {
|
| | | s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
|
| | | // 优化double计算精度丢失问题
|
| | | BigDecimal nNum = new BigDecimal(n);
|
| | | BigDecimal decimal = new BigDecimal(10);
|
| | | BigDecimal scale = nNum.multiply(decimal).setScale(2, RoundingMode.HALF_EVEN);
|
| | | double d = scale.doubleValue();
|
| | | s += (digit[(int) (Math.floor(d * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
|
| | | }
|
| | | if (s.length() < 1)
|
| | | {
|