From c65a84a5abea0476ee0e79894f58ad743f81e03f Mon Sep 17 00:00:00 2001 From: ZhuDongming <773644075@qq.com> Date: Mon, 05 Aug 2019 09:26:39 +0800 Subject: [PATCH] 添加科学计数转为普通计数的方法 --- src/main/java/com/moral/common/util/StringUtils.java | 82 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/moral/common/util/StringUtils.java b/src/main/java/com/moral/common/util/StringUtils.java index 4b2791b..b8b19d3 100644 --- a/src/main/java/com/moral/common/util/StringUtils.java +++ b/src/main/java/com/moral/common/util/StringUtils.java @@ -1,11 +1,25 @@ package com.moral.common.util; +import com.mysql.jdbc.TimeUtil; + +import javax.validation.constraints.NotNull; + +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import org.apache.commons.lang3.Conversion; + +/** + * + * ������������: string ��������� + * @author: fengxiang + * @date: 2018/7/30 10:53 + */ public class StringUtils { public static final char UNDERLINE = '_'; + public static final String NULL = "null"; /** * ������������������������������������������������������ @@ -44,11 +58,10 @@ return sb.toString(); } public static boolean isNullOrEmpty(String toTest) { - return toTest == null || toTest.length() == 0; + return toTest == null || toTest.length() == 0 || NULL.equals(toTest); } public static Object stringToObject4Type(Class<?> type,String value) throws Exception{ Object result = value; - if (type == double.class || type == Double.class) { result = Double.parseDouble(value); } else if (type == float.class || type == Float.class) { @@ -82,4 +95,69 @@ return result; } + /** + * ��������������������������� + * @param str + * @param maxLength + * @return + */ + public static String subStringCN(final String str, final int maxLength) { + if (str == null) { + return str; + } + String suffix = "..."; + int suffixLen = suffix.length(); + + final StringBuffer sbuffer = new StringBuffer(); + final char[] chr = str.trim().toCharArray(); + int len = 0; + for (int i = 0; i < chr.length; i++) { + + if (chr[i] >= 0xa1) { + len += 2; + } else { + len++; + } + } + + if(len<=maxLength){ + return str; + } + + len = 0; + for (int i = 0; i < chr.length; i++) { + + if (chr[i] >= 0xa1) { + len += 2; + if (len + suffixLen > maxLength) { + break; + }else { + sbuffer.append(chr[i]); + } + } else { + len++; + if (len + suffixLen > maxLength) { + break; + }else { + sbuffer.append(chr[i]); + } + } + } + sbuffer.append(suffix); + return sbuffer.toString(); + } + public static boolean isNumericZidai(String str) { + for (int i = 0; i < str.length(); i++) { + //System.out.println(str.charAt(i)); + if (!Character.isDigit(str.charAt(i))) { + return false; + } + } + return true; + } + + public static String scientificCountingConversion(String str){ + BigDecimal db = new BigDecimal(str); + return db.toPlainString(); + } } -- Gitblit v1.8.0