编程常用函数记录

统计在编程中搜索频率较高的Java常用函数,内容来源于编码日常记录.

Java

Math 函数

数值向上取整

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
*
* @Title: formatRMB
* @Description: `分`|转为`元`;并且向上取整
* @param amount
* @return
* String
*/
private String formatRMB(int amount) {
double num = Math.ceil(amount / 100);
if (num % 1.0 == 0) {
return String.valueOf((int) num);
}
return String.valueOf(num);
}

判断(excel)文件类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
   /**
* @Title: isExcel2003
* @Description: 是否为2013的excel,返回true是`.xls`文件
* @param filePath
* @return
* @Return boolean
*/
private boolean isExcel2003(String filePath) {
return filePath.matches("^.+\\.(?i)(xls)$");
}

/**
* @Title: isExcelcsv
* @Description: 是否为csv,返回true:`.csv`文件
* @param filePath
* @return
* @Return boolean
*/
private boolean isExcelcsv(String filePath) {
return filePath.matches("^.+\\.(?i)(csv)$");
}

/**
* @Title: isExcel2007
* @Description: 是否是2007的excel,返回true是2007
* @param filePath
* @return
* @Return boolean
*/
private boolean isExcel2007(String filePath) {
return filePath.matches("^.+\\.(?i)(xlsx)$");
}

JavaScript

限制文本框上传的文件类型

1
$('#element input').attr('accept', ['.xls', '.xlsx', '.csv']);