![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
/**
* 只小数部分四舍五入,整数不进位
* @param d
* @return
*/
public Double checkNumber(Double d){
String[] strArray = d.toString().replace('.',',').split(",");
String left = strArray[0];
String right = strArray[1];
if(right.length()<3){
return d;
}else{
Character char2 = right.charAt(1);
Character char3 = right.charAt(2);
if(char2.equals('9')&&Integer.parseInt(char3.toString())>=5){
return Double.parseDouble(d.toString().substring(0,d.toString().length()-1));
}else{
return Double.parseDouble(formatNumeric(d,0));
}
}
}
* 只小数部分四舍五入,整数不进位
* @param d
* @return
*/
public Double checkNumber(Double d){
String[] strArray = d.toString().replace('.',',').split(",");
String left = strArray[0];
String right = strArray[1];
if(right.length()<3){
return d;
}else{
Character char2 = right.charAt(1);
Character char3 = right.charAt(2);
if(char2.equals('9')&&Integer.parseInt(char3.toString())>=5){
return Double.parseDouble(d.toString().substring(0,d.toString().length()-1));
}else{
return Double.parseDouble(formatNumeric(d,0));
}
}
}
//
数字转逗号分隔字符串,附加小数位数(保留8位小数,那么dec参数为6,即,最少要有2位小数)
public static String formatNumeric( double numeric, int dec) {
String p = "" ;
for ( int i = 0 ; i < dec; i ++ )
p += " # " ;
return formatNumeric(numeric, " #,##0.00 " + p);
}
// 数字转字符串
public static String formatNumeric( double numeric, String pattern) {
if (numeric == - 0 )
numeric = 0 ;
DecimalFormat decFormat = new DecimalFormat(pattern);
return decFormat.format(numeric);
}
public static String formatNumeric( double numeric, int dec) {
String p = "" ;
for ( int i = 0 ; i < dec; i ++ )
p += " # " ;
return formatNumeric(numeric, " #,##0.00 " + p);
}
// 数字转字符串
public static String formatNumeric( double numeric, String pattern) {
if (numeric == - 0 )
numeric = 0 ;
DecimalFormat decFormat = new DecimalFormat(pattern);
return decFormat.format(numeric);
}