Problems often encounter data type during Java development

xiaoxiao2021-03-06  21

(1) In order to resolve this problem, in order to solve this problem, you can get a four-way function Round.

After converting into string, then converted through New BigDecimal ()

For example: fosum = new bigdecimal (string. & # 118alueof (uo1sum.double & # 118alue () Uo2Sum.double & # 118alue (), 3)))))

(2) Convert the time into characters

Java.util.date date = new java.util.date (DATABEAN.GETTYRQ (). gettime ()); SimpleDateFormat SDF = New SimpleDateFormat ("YYYY-MM-DD"); Tyrq = SDF.FORMAT (Date);

(3) Convert the string to time TimeStamp type public java.sql.timestamp startimestamp (string str) {java.sql.timestamp sdate = null;

IF (str! = null) {

IF (str.trim (). Length () == 8) {str = str.substring (0,4) " str.substring (4, 6) " - " Str.Substring (6, 8);

} Try {dateformat df = DateFormat.getdateInstance (DateFormat.Default, java.util.locale.china); java.util.date date = df.parse (STR); sdate = new java.sql.timestamp (Date.gettime) ));} Catch (exception e) {E.PrintStackTrace ();}

} Return SDATE;} (4) Take the Double type into the PUBLIC DOUBLE ROUND (Double V, INT Scale) {

IF (scale <0) {

Throw New IllegalargumentException ("The Scale Must Be a Positive Integer Or Zero");

}

BigDecimal B = New BigDecimal (Double.ToString (V));

BigDecimal One = New BigDecimal ("1");

Return B.divide (One, Scale, BigDecimal.round_half_up) .double & # 118ALUE ();

} (5) Convert INT [] public byte [] INTTOBYTEARRAY (INT NUM) {int Temp = Num; Byte [] b = new byte [6]; for (int i = B.Length; i> -1 i -) {b [i] = new integer (Temp & 0xFF) .Byte & # 118alue (); Temp = Temp >> 8;} return b;} (6) Convert Int to Byte Int S = 0; byte B = (byte) s; transferred from: China University Student Life Network

转载请注明原文地址:https://www.9cbs.com/read-39475.html

New Post(0)