Skip to content

Commit

Permalink
be: clearNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Aug 8, 2023
1 parent 8aebaa8 commit 837605e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/cn/devezhao/persist4j/record/RecordVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import cn.devezhao.persist4j.engine.ID;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.StringReader;
import java.math.BigDecimal;
Expand All @@ -29,6 +31,8 @@
*/
public class RecordVisitor {

private static final Log LOG = LogFactory.getLog(RecordVisitor.class);

public static final String DATE_FORMAT_STRING = "yyyy-MM-dd";
public static final String DATETIME_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";

Expand Down Expand Up @@ -162,7 +166,11 @@ public static String getLiteralByValue(Field field, Object value) {
*/
protected static String clearNumber(String num) {
if (StringUtils.isBlank(num)) return "0";
return num.replace(",", "").trim();
num = num.replace(",", "").trim();
if (NumberUtils.isNumber(num)) return num;

LOG.warn("Bad number format : " + num);
return "0";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public void testClearNumber() {
System.out.println(RecordVisitor.clearNumber("123d "));
System.out.println(RecordVisitor.clearNumber("1,123 "));
System.out.println(RecordVisitor.clearNumber("111,1,11,,123.00 "));
System.out.println(RecordVisitor.clearNumber("NaN"));
}
}

0 comments on commit 837605e

Please sign in to comment.