From bac67218547ae095199d7bcd93fb59928b7f0aae Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Sun, 18 Sep 2016 16:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E7=94=B5=E5=AD=90?= =?UTF-8?q?=E7=97=85=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lyms/platform/common/utils/StringUtils.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java b/platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java index 7407cdd..4c024af 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/StringUtils.java @@ -1,5 +1,8 @@ package com.lyms.platform.common.utils; +import org.apache.commons.lang.math.*; +import org.apache.commons.lang.math.NumberUtils; + import java.util.Date; /** @@ -36,17 +39,37 @@ public final class StringUtils { if (StringUtils.isEmpty(babyWeight)) { return babyWeight; } + + /* if(babyWeight.indexOf('.')>-1){ + Double doubl= NumberUtils.toDouble(babyWeight); + return doubl/1000+""; + }else{ + Integer integer=NumberUtils.toInt(babyWeight); + return ((Double)integer/1000)+""; + }*/ + /* */ + int index = babyWeight.indexOf('.'); + if(index>-1){ + babyWeight = babyWeight.substring(0,index); + } + + if(babyWeight.length()>=4 &&index>-1 &&index<5){ + babyWeight=babyWeight.substring(0,4); + } if (babyWeight.length() <= 3) { babyWeight = org.apache.commons.lang.StringUtils.leftPad(babyWeight, 4, "0"); } StringBuilder stringBuilder = new StringBuilder(babyWeight); - if (babyWeight.length() > 2) { + + if (babyWeight.length() > 2) { stringBuilder.setLength(babyWeight.length() - 1); } stringBuilder.insert(stringBuilder.length() - 2, "."); return stringBuilder.toString(); } - + public static void main(String[] args){ + System.out.println(cutBabyWeight("5000.1")); + } public static Object isEmpty(Object obj, Object defaultVal) { if (null == obj) { return defaultVal; -- 1.8.3.1