How to convert String to Long in Java and matters needing attention

String to Long:

   Long.ValueOf(String); 返回Long包装类

   Long.parseLong(String); 返回long基本数据类型

Precautions:

1. The string cannot contain characters other than numbers

Otherwise, an error will be reported, java.lang.NumberFormatException

2. The length of the string should be limited, otherwise there will be errors

For example: String s = "20160926120625100000", if it exceeds 19 digits, an error will occur and a java.lang.NumberFormatException will be reported

String s = "2016092612062510000", no more than 19 digits will not

The reason is that the maximum value of the Long type is Long.MAX_VALUE = 9223372036854775807, and an error will occur if it is greater than this value

The minimum value of the Long type is Long.MIN_VALUE=-9223372036854775808, and an error will be reported if it is less than this value

Java how to convert string with decimal point to int integer

String douNum ="11.00" ;
int intNum = Double.valueOf(douNum).intValue();

Guess you like

Origin blog.csdn.net/qq_43842093/article/details/123886681