Process | data | data type | problem (1) when converting an int or double to BigDecimal, the number of digits increases accordingly, in order to solve this problem, you can round the double long type by round the
After
, convert to string and then convert it via New BigDecimal ()
For example: Fosum = new BigDecimal (string.& #118alueOf (Round (uo1sum.double& #118alue () + uo2sum.double& #118alue (), 3))
(2) converts time to character
Java.util.Date Date = new Java.util.Date (DATABEAN.GETTYRQ (). GetTime ());
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");
TYRQ = Sdf.format (date);
(3) Converting a string into a time timestamp type
Public Java.sql.Timestamp Strtotimestamp (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) rounding the double type
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 to byte[]
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;