@Test public void testString2Double() { assertEquals(0, TypeUtils.string2Double(null, 0), 5); assertEquals(0, TypeUtils.string2Double("", 0), 5); assertEquals(0, TypeUtils.string2Double("0", 0), 5); assertEquals(0.1, TypeUtils.string2Double("0.1", 0), 5); assertEquals(1.1234, TypeUtils.string2Double("1.1234", 0), 5); assertEquals(1.12345, TypeUtils.string2Double("1.12345", 0), 5); assertEquals(1.12346, TypeUtils.string2Double("1.123456", 0), 5); assertEquals(1.12346, TypeUtils.string2Double("1.123456789", 0), 5); assertEquals(1234.12345, TypeUtils.string2Double("1234.12345", 0), 5); assertEquals(1234.12346, TypeUtils.string2Double("1234.1234567", 0), 5); assertEquals(1234.123451, TypeUtils.string2Double("1234.12345123", 0), 6); }
public static double string2Double(String str, double defaultValue) { try { if (!StringUtils.isBlank(str)) { return Double.parseDouble(str); } } catch (NumberFormatException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format("Parse %s to double fail, default: %f.", str, defaultValue)); } } return defaultValue; }
TypeUtils { public static double string2Double(String str, double defaultValue) { try { if (!StringUtils.isBlank(str)) { return Double.parseDouble(str); } } catch (NumberFormatException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format("Parse %s to double fail, default: %f.", str, defaultValue)); } } return defaultValue; } }
TypeUtils { public static double string2Double(String str, double defaultValue) { try { if (!StringUtils.isBlank(str)) { return Double.parseDouble(str); } } catch (NumberFormatException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format("Parse %s to double fail, default: %f.", str, defaultValue)); } } return defaultValue; } private  TypeUtils(); }
TypeUtils { public static double string2Double(String str, double defaultValue) { try { if (!StringUtils.isBlank(str)) { return Double.parseDouble(str); } } catch (NumberFormatException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format("Parse %s to double fail, default: %f.", str, defaultValue)); } } return defaultValue; } private  TypeUtils(); static int byteArray2Int(byte[] bytes); static long byteArray2Long(byte[] bytes); static byte[] int2ByteArray(int i); static byte[] long2ByteArray(long l); static String byteArray2Ipv4(byte[] bytes); static String byteArray2Ipv6(byte[] bytes); static String byteArray2Ip(byte[] bytes); static List<String> csv2List(String line); static byte[] Ip2byteArrayV4(String ipv4); static byte[] Ip2byteArrayV6(String ipv6); static byte[] Ip2byteArray(String ip); static String byteArray2HexString(byte[] byteArray); static String intArray2HexString(int[] intArray); static String longArray2HexString(int[] longArray); static String byteArray2Base64(byte[] value); static byte[] base642ByteArray(String base64Str); static String byte2HexString(byte b); static byte[] hexString2ByteArray(String input); static boolean string2Boolean(String str, boolean defaultValue); static int string2Int(String str, Radix radix, int defaultValue); static long string2Long(String str, Radix radix, long defaultValue); static float string2Float(String str, float defaultValue); static double string2Double(String str, double defaultValue); static long string2Size(String size, long defaultValue); static long string2TimePeriod(String timePeriod, long defaultValue); static boolean equals(T t1, T t2); static boolean maybeUpdate(T tar, T src); }
TypeUtils { public static double string2Double(String str, double defaultValue) { try { if (!StringUtils.isBlank(str)) { return Double.parseDouble(str); } } catch (NumberFormatException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format("Parse %s to double fail, default: %f.", str, defaultValue)); } } return defaultValue; } private  TypeUtils(); static int byteArray2Int(byte[] bytes); static long byteArray2Long(byte[] bytes); static byte[] int2ByteArray(int i); static byte[] long2ByteArray(long l); static String byteArray2Ipv4(byte[] bytes); static String byteArray2Ipv6(byte[] bytes); static String byteArray2Ip(byte[] bytes); static List<String> csv2List(String line); static byte[] Ip2byteArrayV4(String ipv4); static byte[] Ip2byteArrayV6(String ipv6); static byte[] Ip2byteArray(String ip); static String byteArray2HexString(byte[] byteArray); static String intArray2HexString(int[] intArray); static String longArray2HexString(int[] longArray); static String byteArray2Base64(byte[] value); static byte[] base642ByteArray(String base64Str); static String byte2HexString(byte b); static byte[] hexString2ByteArray(String input); static boolean string2Boolean(String str, boolean defaultValue); static int string2Int(String str, Radix radix, int defaultValue); static long string2Long(String str, Radix radix, long defaultValue); static float string2Float(String str, float defaultValue); static double string2Double(String str, double defaultValue); static long string2Size(String size, long defaultValue); static long string2TimePeriod(String timePeriod, long defaultValue); static boolean equals(T t1, T t2); static boolean maybeUpdate(T tar, T src); static final long KB; static final long MB; static final long GB; static final long TB; static final long PB; static final long SEC; static final long MIN; static final long HOUR; static final long DAY; static final long WEEK; static final long MON; static final long QUAR; static final long YEAR; }