package testa;
import java.math.BigDecimal;
public class test {
/**
* 获取数据 1位小数点
*
* @param st
* @return
*/
public static String get2(String st) {
try {
int i = Integer.parseInt(st);
} catch (Exception e) {
if (!st.contains(".")) {
return "0.00";
}
}
// 整数
if (!st.contains(".")) {
return st + ".00";
}
if ((st.indexOf(".") + 2) == st.length()) {
// 3.1
return st + "0";
}
return st.substring(0, st.indexOf(".") + 3);
}
/**
* int 或者float 相加减
*
* @param d
* @param d1
* @return
*/
public static int addInt(String d, String d1) {
try {
if ((!d.contains(".")) && (!d1.contains("."))) {
return Integer.parseInt(d1) + Integer.parseInt(d);
}
int n = 0;
if (d.contains(".")) {
n = Integer.parseInt(""
+ new BigDecimal(d).setScale(0,
BigDecimal.ROUND_HALF_UP));
} else {
n = Integer.parseInt(d);
}
if (d1.contains(".")) {
n = n
+ Integer.parseInt(""
+ new BigDecimal(d1).setScale(0,
BigDecimal.ROUND_HALF_UP));
} else {
n = n + Integer.parseInt(d1);
}
return n;
} catch (Exception e) {
return 0;
}
}
public static void main(String[] args) {
;
System.out.println(addInt("1.7", "") + "test.main()" + get2("3.121"));
double i = 2, j = 2.1, k = 2.5, m = 2.9;
System.out.println("四舍五入取整:(2)="
+ (3 + Integer.parseInt(""
+ new BigDecimal("222.01").setScale(0,
BigDecimal.ROUND_HALF_UP))));
System.out
.println("四舍五入取整:(2.1)="
+ new BigDecimal("-2.91").setScale(0,
BigDecimal.ROUND_HALF_UP));
System.out
.println("四舍五入取整:(2.5)="
+ new BigDecimal("-2.01").setScale(0,
BigDecimal.ROUND_HALF_UP));
System.out.println("四舍五入取整:(2.9)="
+ new BigDecimal("2.9999999999").setScale(0,
BigDecimal.ROUND_HALF_UP));
String st = "6195169595684291584";
int b = Integer.parseInt(st.substring(st.length() - 5, st.length()));
System.out.println("test.main()" + b);
long tmp = System.currentTimeMillis() / 1000 - (1512376913);
System.out.println("test.main()" + tmp + "\t" + secToTime(11111));
}
public static String secToTime(int time) {
String timeStr = null;
int hour = 0;
int minute = 0;
int second = 0;
if (time <= 0)
return "00:00";
else {
minute = time / 60;
if (minute < 60) {
second = time % 60;
timeStr = unitFormat(minute) + ":" + unitFormat(second);
} else {
hour = minute / 60;
if (hour > 99)
return "99:59:59";
minute = minute % 60;
second = time - hour * 3600 - minute * 60;
timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":"
+ unitFormat(second);
}
}
return timeStr;
}
public static String unitFormat(int i) {
String retStr = null;
if (i >= 0 && i < 10)
retStr = "0" + Integer.toString(i);
else
retStr = "" + i;
return retStr;
}
}