|
|
@ -75,7 +75,7 @@ public class NumberUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Short parseShort(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Short parseShort(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
return Short.valueOf(string); |
|
|
|
return new BigDecimal(string).shortValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).shortValue(); |
|
|
|
return parse(string, contentProperty).shortValue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -89,7 +89,7 @@ public class NumberUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Long parseLong(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Long parseLong(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
return Long.valueOf(string); |
|
|
|
return new BigDecimal(string).longValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).longValue(); |
|
|
|
return parse(string, contentProperty).longValue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -97,26 +97,13 @@ public class NumberUtils { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* parse Integer from string |
|
|
|
* parse Integer from string |
|
|
|
* |
|
|
|
* |
|
|
|
* @param string An integer read in string format |
|
|
|
* @param string An integer read in string format |
|
|
|
* @param contentProperty Properties of the content read in |
|
|
|
* @param contentProperty Properties of the content read in |
|
|
|
* @return An integer converted from a string |
|
|
|
* @return An integer converted from a string |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Integer parseInteger(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Integer parseInteger(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
// CS304 Issue link: https://github.com/alibaba/easyexcel/issues/2443
|
|
|
|
return new BigDecimal(string).intValue(); |
|
|
|
int stringLength = string.length(); |
|
|
|
|
|
|
|
if(stringLength>0){ |
|
|
|
|
|
|
|
int pointer = stringLength; |
|
|
|
|
|
|
|
for(int i=0;i<stringLength;i++){ |
|
|
|
|
|
|
|
if(string.charAt(i)=='.'){ |
|
|
|
|
|
|
|
pointer = i; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string = string.substring(0,pointer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Integer.valueOf(string); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).intValue(); |
|
|
|
return parse(string, contentProperty).intValue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -130,7 +117,7 @@ public class NumberUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Float parseFloat(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Float parseFloat(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
return Float.valueOf(string); |
|
|
|
return new BigDecimal(string).floatValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).floatValue(); |
|
|
|
return parse(string, contentProperty).floatValue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -159,7 +146,7 @@ public class NumberUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Byte parseByte(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Byte parseByte(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
return Byte.valueOf(string); |
|
|
|
return new BigDecimal(string).byteValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).byteValue(); |
|
|
|
return parse(string, contentProperty).byteValue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -173,7 +160,7 @@ public class NumberUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Double parseDouble(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
public static Double parseDouble(String string, ExcelContentProperty contentProperty) throws ParseException { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
if (!hasFormat(contentProperty)) { |
|
|
|
return Double.valueOf(string); |
|
|
|
return new BigDecimal(string).doubleValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
return parse(string, contentProperty).doubleValue(); |
|
|
|
return parse(string, contentProperty).doubleValue(); |
|
|
|
} |
|
|
|
} |
|
|
|