android中如何实现除法的保留小数点后2位,四舍五入!
来源:学生作业帮 编辑:大师作文网作业帮 分类:英语作业 时间:2024/10/03 17:12:08
android中如何实现除法的保留小数点后2位,四舍五入!
static long round(double a) Returns the closest long to the argument.
static int round(float a) Returns the closest int to the argument
精确的,是这样.
/**
* 提供精确的小数位四舍五入处理.
*
* @param v
* 需要四舍五入的数字
* @param scale
* 小数点后保留几位
* @return 四舍五入后的结果
*/
public static double round(Double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero");
}
BigDecimal b = null == v ? new BigDecimal("0.0") : new BigDecimal(Double.toString(v));
BigDecimal one = new BigDecimal("1");
return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
再问: 能不能给一个最简单的Java例子!麻烦你了!
再答: 拜托了,android的例子,在android安装目录有不少,有简单、有容易的,用上这段就可以了。
static int round(float a) Returns the closest int to the argument
精确的,是这样.
/**
* 提供精确的小数位四舍五入处理.
*
* @param v
* 需要四舍五入的数字
* @param scale
* 小数点后保留几位
* @return 四舍五入后的结果
*/
public static double round(Double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero");
}
BigDecimal b = null == v ? new BigDecimal("0.0") : new BigDecimal(Double.toString(v));
BigDecimal one = new BigDecimal("1");
return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
再问: 能不能给一个最简单的Java例子!麻烦你了!
再答: 拜托了,android的例子,在android安装目录有不少,有简单、有容易的,用上这段就可以了。
vb中如何设置整数保留小数点后一位小数,小数四舍五入保留两位小数
Excel中如何将公式计算出的数值四舍五入后只保留2位小数,之后再用这几个数值相加也只是小数点后2位相加
C语言如何实现将一个小数点后100位的小数按小数点后99位四舍五入输出
在EXCEL表格中如何实现数字后加上竖线,并且数字保留小数点后2位?
如何让Excel四舍五入,并且保留2位小数点
Excel 函数是否可以实现保留一位小数点,并且第2位小数点不进行四舍五入
四舍五入是怎么计算的648,09465保留小数点后2位数字
C语言中怎样输入一个双精度数,对小数点后第2位进行四舍五入,即保留一位小数,输出四舍五入的结果.
c语言中浮点数四舍五入 .保留一个浮点数小数点后的6位,第3位要四舍五入.如 1.1234.567到1234.57000
excel小于1的保留两位小数点,大于1的保留整数,excel中如何实现
excel2007中如何四舍五入并且保留四位小数点,前两位为四舍五入数值,后两位数值为0
excel 小数点保留2位 第三位则四舍五入,而不是无限制进上去的!