package traffic.model.format;
/**
* 此类专门用来处理小数位数
*
* @author 邹政
*
* @since Traffic 1.0
* */
public final class DoubleProcess {
/**保留一位小数*/
public static double toOnePointNumber(double value) {
if ((int)(value*100)%10 >= 5){
value = ((int)(value*10)+1)/10.0;
}else {
value = (int)(value*10)/10.0;
}
return value;
}
/**保留两位小数*/
public static double toTwoPointNumber(double value) {
if ((int)(value*1000)%10 >= 5){
value = ((int)(value*100)+1)/100.0;
}else {
value = (int)(value*100)/100.0;
}
return value;
}
/**保留三位小数*/
public static double toThreePointNumber(double value) {
if ((int)(value*10000)%10 >= 5){
value = ((int)(value*1000)+1)/1000.0;
}else {
value = (int)(value*1000)/1000.0;
}
return value;
}
/**保留四位小数*/
public static double toFourPointNumber(double value) {
if ((int)(value*100000)%10 >= 5){
value = ((int)(value*10000)+1)/10000.0;
}else {
value = (int)(value*10000)/10000.0;
}
return value;
}
/**寻找一维数组的最小值*/
public static double getMinValueOfOneArrays(double[] value) {
double min = value[0];
for (int i=1; i
if (min > value[i]) {
min = value[i];
}
}
return min;
}
/**寻找一维数组的最大值*/
public static double getMaxValueOfOneArrays(double[] value) {
double max = value[0];
for (int i=1; i
if (max < value[i]) {
max = value[i];
}
}
return max;
}
/**寻找二维数组的最小值*/
public static double getMinValueOfTwoArrays(double[][] value) {
double min = value[0][0];
for (int i=0; i
for (int j=0; j
if (min > value[i][j]) {
min = value[i][j];
}
}
}
return min;
}
/**寻找二维数组的最大值*/
public static double getMaxValueOfTwoArrays(double[][] value) {
double max = value[0][0];
for (int i=0; i
for (int j=0; j
if (max < value[i][j]) {
max = value[i][j];
}
}
}
return max;
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。